Just for anyone information, there is a similar title "Search in Listbox" but it is via Combo Box. In case, anyone need it, I put a link to there.
Please let me know if I break any rules by posting a link so then, I will remove it.
Okay, here is my question. If you ever refer to the link, I am almost doing the same thing. Just that, I am doing a textbox and a combo box to search the listed data in the listbox.
The listbox consist of multiple column (PartID, Category, Engine, Model, Brand [Source from a Query]). When user like to search, he/she can choose the combo-box (for which column to search) and type in the textbox, and finally press the Search button. Then the listbox will locate the closest/exact match and select/highlight it. A note, not filter but the listbox will Go To The Specific Data and Select/Highlight It.
My Listbox RowSource:
SELECT DISTINCTROW PartID, Category, Engine, Model, Brand FROM EX ORDER BY PartID;
Private Sub cmdRun2_Click()
Dim i As Integer
Dim A As Integer
Dim txtSelect1 As String
Dim response As Integer
For i = 0 To listPart.ListCount - 1
'To determine Selected-Combo-Box and the Search Column of the listbox
If qSelect1 = "PartID" Then
A = 0
ElseIf qSelect1 = "Category" Then
A = 1
ElseIf qSelect1 = "Engine" Then
A = 2
ElseIf qSelect1 = "Model" Then
A = 3
ElseIf qSelect1 = "Brand" Then
A = 4
listPart.Selected(i) = False
'Able to find the closest match
txtSelect1 = "" & txtSelect1 & " * "
'After it determine which Column to search, "A" represent it
If listPart.Column(A, i) Like txtSelect1 Then
listPart.Selected(i) = True
'After the data had been search & selected, it will auto Order By
response = listOrderBy(qSelect1, "ASC")
The problem is I'm not really sure what happened. No highlighted search result after press "Search". No Error.
If you refer to the Top-Link (Search in Listbox via Combo), I try to replicate the way it code. Still, not working.
Hope someone can help. I don't mind a new way to code this, just let me know. Thanks in advance.