VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Select List Box or Combo Box Value by Index

by Cierra Computers & Consulting (5 Submissions)
Category: Custom Controls/Forms/Menus
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (2 Votes)

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

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

Download this snippet    Add to My Saved Code

Select List Box or Combo Box Value by Index Comments

No comments have been posted about Select List Box or Combo Box Value by Index. Why not be the first to post a comment about Select List Box or Combo Box Value by Index.

Post your comment

Subject:
Message:
0/1000 characters