View Full Version : Disable editing in form fields?
clhare
07-30-2010, 10:05 AM
I have a document that contains form fields (both text fields and dropdown files). Is there a way to convert the values in the form fields to actual text so I can lock the file created with a password so the user can't edit it in any way? I know that the fields are still editable if I lock the file as is. I need to ensure that the user can't make any changes to the final document.
Any help is greatly appreciated!
fumei
07-30-2010, 10:44 AM
Let me get this straight.
You have formfields so the user can enter text, or choose dropdown items.
At some point (undefined) you want to convert the formfields into plain text, and then locked it fully allowing NO changes whatsoever.
Ok, probably.
Are you aware thought that if the document is greater than one screen the user will NOT be able to see anything past that screen? So if your document has two pages the user will never be allowed to see page 2. Locking it fully means the cursor (Selection) can not go to the locked sections. if the surcor can not go there....neither can that part be visible on screen, as what is one screen is what is visible with the cursor.
What have you tried? You have been doing this enough that you should be able to give it a shot. It is not hard at all.
Sub CovertFF2_Text()
Dim DocFF As FormFields
Dim oFF As FormField
Dim r As Range
ActiveDocument.Unprotect
Set DocFF = ActiveDocument.FormFields
For Each oFF In DocFF
Set r = oFF.Range
With r
.Move Unit:=wdCharacter, Count:=-1
r.Text = oFF.Result
oFF.Delete
End With
Next oFF
ActiveDocument.Protect wdAllowOnlyFormFields
End Sub
fumei
07-30-2010, 10:46 AM
I would like to add that your subject:
Disable editing in form fields
is NOT what you are asking about. You are asking:
" Is there a way to convert the values in the form fields to actual text"
That is nto the same as disabling editing. Please try and be as explicit and specific as possible.
clhare
07-30-2010, 11:04 AM
Sorry about that. I guess I'm not quite sure how I would go about this. Essentially, I do want the user to be able to scroll through the document, but I also want to be sure that they can't edit it in any way once it is final. That's why I was thinking I have to switch the forms fields to text. If I lock the file, the fields can still be edited. I think if I convert the field values to text, then I can protect the document (with a password) so they can see the entire document without being able to change it. Hopefully!
fumei
07-30-2010, 11:27 AM
"then I can protect the document (with a password) so they can see the entire document without being able to change it. Hopefully!"
The ONLY way to see the whole document is with the scrollbars. Which may be acceptable for you. PageDown works only to the extent of the last page reaches the top of the screen. Anything below what is visible on reaching that page is not visible with pagedown. Again the scrollbars do work.
Take a look at the demo. It is protected for forms. Put some text into the first formfield, make a selection on the dropdown. Click "Convert FF_2Text" on the top toolbar.
Your text input in the text formfield is convert to plain text. Your item selected from the dropdown is converted to plain text. Now see what is avilable in terms of scrolling and/or pagedown.
Also note that if you try and put the cursor anywhere it jumps back to the start of the document.
That is simply the way it works.
Tinbendr
07-30-2010, 02:28 PM
You can disable Fromfields by
Activedocuments.Formfield("FFName").Enabled = False
Also, You can always print to a PDF.
gmaxey
07-30-2010, 02:58 PM
Gerry,
Curious as to why you bother with using range for the the text and dropdown fields?
I had to hunt around awhile to find this code example but you might consider:
Sub ConvertFormFieldsToText()
Dim oFld As Field
Dim oRng As Word.Range
Dim bChecked As Boolean
If ActiveDocument.ProtectionType <> wdNoProtection Then ActiveDocument.Unprotect
For Each oFld In ActiveDocument.Range.Fields
Select Case oFld.Type
Case wdFieldFormTextInput
oFld.Unlink
Case wdFieldFormDropDown
oFld.Unlink
Case wdFieldFormCheckBox
oFld.Select
bChecked = Selection.FormFields(1).CheckBox.Value
oFld.Delete
Set oRng = Selection.Range
Select Case bChecked
Case True
oRng.InsertSymbol 254, "Wingdings"
Case Else
oRng.InsertSymbol 168, "Wingdings"
End Select
End Select
Next
End Sub
fumei
07-30-2010, 03:26 PM
1. darn, I forgot about checkboxes, and how to deal with that!!!
2. going at it from a different angle. You are actioning them as fields. I was actioning them as formfields.
Sub CovertFF2_Text()
Dim DocFF As FormFields
Dim oFF As FormField
Dim r As Range
ActiveDocument.Unprotect
Set DocFF = ActiveDocument.FormFields
For Each oFF In DocFF
Set r = oFF.Range
r.Move Unit:=wdCharacter, Count:=-1
Select Case oFF.Type
Case 70, 83
With r
r.Text = oFF.Result
oFF.Delete
End With
Case 71
Select Case oFF.CheckBox.Value
Case -1
r.InsertSymbol 254, "Wingdings"
oFF.Delete
Case 0
r.InsertSymbol 254, "Wingdings"
oFF.Delete
End Select
End Select
Next oFF
ActiveDocument.Protect wdAllowOnlyFormFields
End Sub
Fortunately for us all, VBA has many ways to end up with the same result...sometimes.
Specifically though it has something to do with your:
oFld.Select
I avoid using selection as much as possible. If that particular checkbox was not on the current page, the GUI would jump to that page. Yes you can not do a refresh/update yadda yadda yadda. I simply prefer not bothering with Selection unless I absolutely have to (and we both know there ARE a few rare cases when this is true).
Not saying my way is better. Your use of fields is elegant...and more importantly, it works (of course).
Shrug...what can I say?
Darn I forgot the checkbox thing though, that kind of ticks me. Dummy.
gmaxey
07-30-2010, 06:33 PM
Selection aversion. Got it ;-). I understand. I try not to use it either, but found it handy here.
You have the same number in both case here:
Case -1
r.InsertSymbol 254, "Wingdings"
oFF.Delete
Case 0
r.InsertSymbol 254, "Wingdings"
oFF.Delete
gmaxey
07-30-2010, 07:07 PM
You got me to thinking. We don't need a range variable or the selection.
Sub ConvertFormFieldsToText()
Dim oFF As FormField
If ActiveDocument.ProtectionType <> wdNoProtection Then ActiveDocument.Unprotect
For Each oFF In ActiveDocument.FormFields
If oFF.Type = wdFieldFormTextInput Or oFF.Type = wdFieldFormDropDown Then
oFF.Range.Fields(1).Unlink
ElseIf oFF.Type = wdFieldFormCheckBox Then
If oFF.CheckBox.Value = True _
Then oFF.Range.InsertSymbol 254, "Wingdings" _
Else: oFF.Range.InsertSymbol 168, "Wingdings"
End If
Next
End Sub
Done in 10 lines of cod or less. Any bonus points ;-)
clhare
08-02-2010, 08:58 AM
This is really cool! The only field that didn't get converted to text is in a frame on the first page (there is a field in the frame for the filename of the template used to generate the document). How would I catch that field as well?
clhare
08-02-2010, 09:13 AM
Oh.... and our first idea was to generate a pdf file of the document, but unfortunately some users do not have Adobe, so that part of the macro wouldn't work for them. So now I need to come up with another way to create a document that cannot be edited. It will later be emailed as an attachment instead of actually printed and mailed, so we don't want the recipient to be able to change its content.
fumei
08-03-2010, 02:26 PM
Greg. Major bonus points! I like it.
Cheryl, ack, you keep tossing out unstated issues. A formfield in a frame???? Ack!
"It will later be emailed as an attachment instead of actually printed and mailed, so we don't want the recipient to be able to change its content."
This is not truly possible. If someone really wanted to change it, and they have the file....they can change it. No Office file is secure. Period. The issue is how much they may want to work at it.
"The only field that didn't get converted to text is in a frame on the first page (there is a field in the frame for the filename of the template used to generate the document). How would I catch that field as well?"
Why on earth would this be a formfield?????????????
clhare
08-09-2010, 04:15 AM
Sorry... I did resolve the formfield in a frame issue by using search and replace. It wasn't my idea to put it in a frame, and I agree... it's a pain to have it there.
Now I'm nervous about the Word doc. I wish all the users had Adobe. I'll create another post re converting a Word file to Adobe (in case that becomes the option of choice). Thanks for your help on this!
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.