PDA

View Full Version : drop down form field menu not appearing under condition



OTWarrior
09-12-2007, 03:18 AM
I am using a dropdown form field, and if a specific option is choosen, then clear the list and re-popluate. I want the user to stay in the drop down box (and for the drop down menu to appear until they select a different option) and I almost have it. When "...Previous List" or "..Next List..." is choosen, the code works perfectly, the problem lies when you have are in the box, and to select the "...Previous List" or "..Next List..." option, it doesn't excute the drop down menu (which happens when SendKeys "%({DOWN})", True is run), so only seems to work the once for everytime you manually enter the form field.



Dim BKMName As String


Public Sub AOnEntry()

If ActiveDocument.FormFields(BKMName).Result = "Select an option" Then
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
Selection.Range.HighlightColorIndex = wdNoHighlight
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If

Exit Sub
ElseIf ActiveDocument.FormFields(BKMName).Result = "..Next List..." Or _
ActiveDocument.FormFields(BKMName).Result = "..." Then

ActiveDocument.FormFields(BKMName).Select
ActiveDocument.FormFields(BKMName).DropDown.ListEntries.Clear
ActiveDocument.FormFields(BKMName).DropDown.ListEntries.Add "Select an option"

For x = 1 To 20
ActiveDocument.FormFields(BKMName).DropDown.ListEntries.Add Str(x)
Next
ActiveDocument.FormFields(BKMName).DropDown.ListEntries.Add "...Previous List"
ActiveDocument.FormFields(BKMName).DropDown.Value = 1

If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
Selection.Range.HighlightColorIndex = wdYellow
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If
SendKeys "%({DOWN})", True
Exit Sub
ElseIf ActiveDocument.FormFields(BKMName).Result = "...Previous List" Or _
ActiveDocument.FormFields(BKMName).Result = "..." Then


ActiveDocument.FormFields(BKMName).Select
ActiveDocument.FormFields(BKMName).DropDown.ListEntries.Clear
ActiveDocument.FormFields(BKMName).DropDown.ListEntries.Add "Select an option"

For x = 21 To 40
ActiveDocument.FormFields(BKMName).DropDown.ListEntries.Add Str(x)
Next
ActiveDocument.FormFields(BKMName).DropDown.ListEntries.Add "..Next List..."
ActiveDocument.FormFields(BKMName).DropDown.Value = 1

If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
Selection.Range.HighlightColorIndex = wdYellow
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If
SendKeys "%({DOWN})", True
Exit Sub
Else
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
Selection.Range.HighlightColorIndex = wdNoHighlight
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If

Exit Sub
End If
End Sub

Public Sub AOnExit()
If BKMName = "" Then
BKMName = "Dropdown1"
Else
'BKMname = BKMname
End If
If ActiveDocument.FormFields(BKMName).Result = "..." Or _
ActiveDocument.FormFields(BKMName).Result = "...Previous List" Or _
ActiveDocument.FormFields(BKMName).Result = "..Next List..." Then
Call AOnEntry
ActiveDocument.FormFields(BKMName).Select
SendKeys "%{DOWN}"
End If
End Sub

Any help would be much appreciated, as this is the last problem on a project that has taken me 3 months.

Unless there is a certain option i have yet to add...i am stumped :dunno