I have a Breeders table that you could think of as being like a contacts table or address book and a Breed table for all the different breeds (there will only be 10-12 in this application).
When the window opens to maintain the Breeders table, a method runs to load the list of breeds in a popup menu with all the Breed Names. The user then selects the appropriate breed for the selected Breeder and the text value of Breed Name is written to the database record. Now when the user comes back later to update the Breeders and I load the TextFields on the window with the database values. How do I set the popupmenu.index to the entry that matches the breed in the database record?
Is there a better way to do this but I like the popup menu for it?
When we want to set the popup menu to the correct ID (because your really want to work with ID’s the than text in the database) we call this:
Public Sub SetFromRowTag(extends pm as PopupMenu, tag as Variant)
for i as integer = 0 to pm.ListCount-1
if pm.RowTag(i) = tag then
pm.ListIndex = i
return
end
next
End Sub
Usage: PopupMenu1.SetFromRowTag(2) //Will set to second value.
If you must set by text we do this:
Public Sub SetText(extends pm as PopupMenu, text as String)
for i as integer = 0 to pm.ListCount -1
if pm.list(i) = text then
pm.ListIndex = i
exit
end
next
End Sub
Usage: Popupmenu1.SetText(“First Value”)
I find the extends to be simpler to use because you don’t need the subclass and AutoComplete still works with it.