Thread: [Solved] Help with if then statements
View Single Post
 
Old 07-13-2015, 11:00 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,375
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Inserting the new item is easy enough, but you also need to be able to delete it again if the user changes the dropdown selection. The following code should suffice. See attached demo.
Code:
Sub OptTxtFmFld()
Dim Prot As Variant, BmkRng As Range
Const Pwd As String = "" 'Insert password here
Const BmkNm As String = "BkMk" ' The bookmark name
With ActiveDocument
  Prot = .ProtectionType
  If .ProtectionType <> wdNoProtection Then
    Prot = .ProtectionType
    .Unprotect Password:=Pwd
  End If
  If .Bookmarks.Exists(BmkNm) Then
    Set BmkRng = .Bookmarks(BmkNm).Range
    If .FormFields("Dropdown1").Result = "1000" Then
      .FormFields.Add BmkRng, wdFieldFormTextInput
    Else
      BmkRng.Delete
    End If
    .Bookmarks.Add BmkNm, BmkRng
  Else
    MsgBox "Bookmark: " & BmkNm & " not found."
  End If
  .Protect Type:=Prot, Password:=Pwd, NoReset:=True
End With
Set BmkRng = Nothing
End Sub
Attached Files
File Type: docm FormFieldDemo.docm (30.5 KB, 23 views)
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote