Bra Utbildning AB

 

<-- Back
VBA & Object models
Work with text
Bookmarks
Ranges
Fields
Form fields
Autotext
Doc var & Doc Prop
Built-in commands
Built-in dialogs
Automation
External databases

Work with forms and form fields


Set field result with code
ActiveDocument.Formfields("Lastname").Result = "any text"
ActiveDocument.Formfields("Checkbox1").Result = 1
ActiveDocument.Formields("Checkbox1").CheckBox.Value = True
ActiveDocument.Formfields("DropDown1").Result = "a value on the list"
ActiveDocument.Formfields("DropDown1).DropDown.Value = 4

Get the result/contents from a form field
MsgBox ActiveDocument.Formfields("Lastname").Result

Unprotect a protected document
Dim oDoc As Document

Set oDoc = ActiveDocument
If Not oDoc.ProtectionType = wdNoProtection Then
   oDoc.Unprotect
End If

Protect a form, prevent the form from loosing added data, and add password to access the form
Dim oDoc As Document

Set oDoc = ActiveDocument
If oDoc.ProtectionType = wdNoProtection Then
   oDoc.Protect _
               Type:=wdAllowOnlyFormFields, _
               NoReset:=True, _
               Password:="Any Password"
End If