Advertisement
ASP_Volume3 Custom Controls/ Forms/ Menus #45263

Select List Box or Combo Box Value by Index

This function will select the value of a List Box or Combo Box based upon the Index ID. This is helpful when you are trying to edit a record and want to select a saved value in a combo box or list box.

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
Public Sub SelectInList(varID As Variant, ctlList As Control, Optional ctl As CtlType, _
   Optional blnRefresh As Boolean = True)
'Selects the Item in List or Combo Box that matches passed varID
Dim x
If Not IsNull(varID) Then
   varID = CLng(varID)
     
   If blnRefresh = True Then
     ctlList.Refresh
   End If
   
   For x = 0 To ctlList.ListCount - 1
     If ctlList.ItemData(x) = varID Then
        If ctl = ListBox Then
          ctlList.Selected(x) = True
        Else
          ctlList = ctlList.List(x)
        End If
        Exit Sub
     End If
   Next
Else
   'Reset the ComboBox
   ctlList.ListIndex = -1
End If
End Sub
Original Comments (3)
Recovered from Wayback Machine