OTWarrior
08-30-2007, 08:35 AM
I have a multitude of drop down form fields on a document that will be used by people of different skill levels, so want to make it as easy as possible.
since drop down form fields have a limit of 25 items, i clear the list if the last item is chosen and rebuild it from an array. To make sure the user is aware that it is a new list in the drop down, I want the drop down box to be selected again and to drop down the menu.
I know how to do this if the user "tabs out", but if use the mouse to select anyway else other than the next box, it can look very confusing.
the macro is run on exit, and looks something like this:
********************
Sub filler()
On Error Resume Next
Dim Data3 As Variant
Data3 = Array("info", "main list..")
Dim Data4 As Variant
Data4 = Array("info2", "main list..")
Dim Data5 As Variant
Data5 = Array("info3", "main list..")
Dim LocData As Variant 'default loading list
LocData = Array("Select an option..", "list1..", "list2...", "list3...")
Dim j As Integer, j2 As Integer, j3 As Integer, iProvLoop As Integer
Dim BKMname2 As String
If Selection.FormFields.Count = 1 Then
'No textbox but a check- or listbox
BKMname2 = Selection.FormFields(1).Name
ElseIf Selection.FormFields.Count = 0 And Selection.Bookmarks.Count > 0 Then
BKMname2 = Selection.Bookmarks(Selection.Bookmarks.Count).Name
End If
Dim DefaultList As String
DefaultList = LBound(LocData)
Dim Dropper As String
Dropper = "%{down}"
If ActiveDocument.FormFields(BKMname2).Result = "main list.." Then
ActiveDocument.FormFields(BKMname2).DropDown.ListEntries.Clear
For iProvLoop = DefaultList To UBound(LocData)
ActiveDocument.FormFields(BKMname2).DropDown.ListEntries.Add LocData(iProvLoop)
Next iProvLoop
ActiveDocument.FormFields(BKMname2).DropDown.Value = 1
SendKeys "{LEFT}"
SendKeys Dropper
Exit Sub
ElseIf ActiveDocument.FormFields(BKMname2).Result = LocData(DefaultList + 3) Then
ActiveDocument.FormFields(BKMname2).DropDown.ListEntries.Clear
ActiveDocument.FormFields(BKMname2).DropDown.ListEntries.Add "Select list1 option"
For j = LBound(Data5) To UBound(Data5)
ActiveDocument.FormFields(BKMname2).DropDown.ListEntries.Add Data5(j)
Next j
ActiveDocument.FormFields(BKMname2).DropDown.Value = 1
SendKeys "{LEFT}"
SendKeys Dropper
Exit Sub
ElseIf ActiveDocument.FormFields(BKMname2).Result = LocData(DefaultList + 2) Then
ActiveDocument.FormFields(BKMname2).DropDown.ListEntries.Clear
ActiveDocument.FormFields(BKMname2).DropDown.ListEntries.Add "Select list2 option"
For j2 = LBound(Data4) To UBound(Data4)
ActiveDocument.FormFields(BKMname2).DropDown.ListEntries.Add Data4(j2)
Next j2
ActiveDocument.FormFields(BKMname2).DropDown.Value = 1
SendKeys "{LEFT}"
SendKeys Dropper
Exit Sub
ElseIf ActiveDocument.FormFields(BKMname2).Result = LocData(DefaultList + 1) Then
ActiveDocument.FormFields(BKMname2).DropDown.ListEntries.Clear
ActiveDocument.FormFields(BKMname2).DropDown.ListEntries.Add "Select list3 option"
For j3 = LBound(Data3) To UBound(Data3)
ActiveDocument.FormFields(BKMname2).DropDown.ListEntries.Add Data3(j3)
Next j3
ActiveDocument.FormFields(BKMname2).DropDown.Value = 1
SendKeys "{LEFT}"
SendKeys Dropper
Exit Sub
Else
Exit Sub
End If
End Sub
********************
as you can see, i am selecting the box again (SendKeys "{LEFT}") then calling the drop down box (SendKeys Dropper). But how would I specifically select the box i have just left?
I have tried :
ActiveDocument.FormFields(BKMname2).Range.Select
Selection.GoTo What:=wdGoToBookmark, Name:=BKMname2
ActiveDocument.Bookmarks(BKMname2).Range.Fields(1).Result.Select
...And none of these seem to select the form field.
What am I doing wrong?
since drop down form fields have a limit of 25 items, i clear the list if the last item is chosen and rebuild it from an array. To make sure the user is aware that it is a new list in the drop down, I want the drop down box to be selected again and to drop down the menu.
I know how to do this if the user "tabs out", but if use the mouse to select anyway else other than the next box, it can look very confusing.
the macro is run on exit, and looks something like this:
********************
Sub filler()
On Error Resume Next
Dim Data3 As Variant
Data3 = Array("info", "main list..")
Dim Data4 As Variant
Data4 = Array("info2", "main list..")
Dim Data5 As Variant
Data5 = Array("info3", "main list..")
Dim LocData As Variant 'default loading list
LocData = Array("Select an option..", "list1..", "list2...", "list3...")
Dim j As Integer, j2 As Integer, j3 As Integer, iProvLoop As Integer
Dim BKMname2 As String
If Selection.FormFields.Count = 1 Then
'No textbox but a check- or listbox
BKMname2 = Selection.FormFields(1).Name
ElseIf Selection.FormFields.Count = 0 And Selection.Bookmarks.Count > 0 Then
BKMname2 = Selection.Bookmarks(Selection.Bookmarks.Count).Name
End If
Dim DefaultList As String
DefaultList = LBound(LocData)
Dim Dropper As String
Dropper = "%{down}"
If ActiveDocument.FormFields(BKMname2).Result = "main list.." Then
ActiveDocument.FormFields(BKMname2).DropDown.ListEntries.Clear
For iProvLoop = DefaultList To UBound(LocData)
ActiveDocument.FormFields(BKMname2).DropDown.ListEntries.Add LocData(iProvLoop)
Next iProvLoop
ActiveDocument.FormFields(BKMname2).DropDown.Value = 1
SendKeys "{LEFT}"
SendKeys Dropper
Exit Sub
ElseIf ActiveDocument.FormFields(BKMname2).Result = LocData(DefaultList + 3) Then
ActiveDocument.FormFields(BKMname2).DropDown.ListEntries.Clear
ActiveDocument.FormFields(BKMname2).DropDown.ListEntries.Add "Select list1 option"
For j = LBound(Data5) To UBound(Data5)
ActiveDocument.FormFields(BKMname2).DropDown.ListEntries.Add Data5(j)
Next j
ActiveDocument.FormFields(BKMname2).DropDown.Value = 1
SendKeys "{LEFT}"
SendKeys Dropper
Exit Sub
ElseIf ActiveDocument.FormFields(BKMname2).Result = LocData(DefaultList + 2) Then
ActiveDocument.FormFields(BKMname2).DropDown.ListEntries.Clear
ActiveDocument.FormFields(BKMname2).DropDown.ListEntries.Add "Select list2 option"
For j2 = LBound(Data4) To UBound(Data4)
ActiveDocument.FormFields(BKMname2).DropDown.ListEntries.Add Data4(j2)
Next j2
ActiveDocument.FormFields(BKMname2).DropDown.Value = 1
SendKeys "{LEFT}"
SendKeys Dropper
Exit Sub
ElseIf ActiveDocument.FormFields(BKMname2).Result = LocData(DefaultList + 1) Then
ActiveDocument.FormFields(BKMname2).DropDown.ListEntries.Clear
ActiveDocument.FormFields(BKMname2).DropDown.ListEntries.Add "Select list3 option"
For j3 = LBound(Data3) To UBound(Data3)
ActiveDocument.FormFields(BKMname2).DropDown.ListEntries.Add Data3(j3)
Next j3
ActiveDocument.FormFields(BKMname2).DropDown.Value = 1
SendKeys "{LEFT}"
SendKeys Dropper
Exit Sub
Else
Exit Sub
End If
End Sub
********************
as you can see, i am selecting the box again (SendKeys "{LEFT}") then calling the drop down box (SendKeys Dropper). But how would I specifically select the box i have just left?
I have tried :
ActiveDocument.FormFields(BKMname2).Range.Select
Selection.GoTo What:=wdGoToBookmark, Name:=BKMname2
ActiveDocument.Bookmarks(BKMname2).Range.Fields(1).Result.Select
...And none of these seem to select the form field.
What am I doing wrong?