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.
API Declarations
Public Enum CtlType
ListBox
ComboBox
End Enum
Rate Select List Box or Combo Box Value by Index
(2(2 Vote))
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
Select List Box or Combo Box Value by Index Comments
No comments yet — be the first to post one!
Post a Comment