Consulting

Results 1 to 1 of 1

Thread: drop down form field menu not appearing under condition

  1. #1
    VBAX Mentor OTWarrior's Avatar
    Joined
    Aug 2007
    Location
    England
    Posts
    389
    Location

    drop down form field menu not appearing under condition

    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 [vba]SendKeys "%({DOWN})", True[/vba] is run), so only seems to work the once for everytime you manually enter the form field.



    [vba]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[/vba]

    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
    Last edited by OTWarrior; 09-12-2007 at 03:35 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •