hi,
I'm sure this is very simple. I just can't seem to figure it out.
I have a listbox with around 500+ items that the user chooses from. I have a button called "Find" that looks for a search string in the listbox (that way the users won't have to scroll through the items to look for something).
The "Find" button works well - the user enters a string to search, clicks ok and the row where the string exists is 'highlighted'. Here's my problem: I would like to keep asking the user if they want to continue searching for the word (just like the Find function in the menu bar).
Here is the code :
I've tried setting flags, and now I'm calling the function again but this doesn't seem to select the row first before displaying the Inputbox again.
Can anyone help? Please?
Thank you in advance.
I'm sure this is very simple. I just can't seem to figure it out.
I have a listbox with around 500+ items that the user chooses from. I have a button called "Find" that looks for a search string in the listbox (that way the users won't have to scroll through the items to look for something).
The "Find" button works well - the user enters a string to search, clicks ok and the row where the string exists is 'highlighted'. Here's my problem: I would like to keep asking the user if they want to continue searching for the word (just like the Find function in the menu bar).
Here is the code :
Code:
Private Sub cmdFind_Click()
'The code below will search for a string and set the row to that string
Const NumRows = 20
Dim intDesiredRow As Integer
Dim strSearch As String
Dim i As Long
Dim iContinueSearch As Integer
strSearch = InputBox("Enter keyword to search")
strSearch = "*" & strSearch & "*"
If List1.ListCount > 0 Then
For i = 0 To Me.List1.ListCount
If List1.Column(1, i) Like strSearch Then
intDesiredRow = i
i = Me.List1.ListCount
'Set Focus
Me.List1.SetFocus
Me.List1.ListIndex = 1
'Offset
Me.List1.ListIndex = intDesiredRow + (NumRows - 1)
Me.List1.ListIndex = intDesiredRow - 1
End If
Next i
End If
iContinueSearch = MsgBox("Do you want to continue searching?", vbQuestion + vbYesNo)
If iContinueSearch = vbNo Then
Exit Sub
Else
cmdFind_Click
End If
End Sub
I've tried setting flags, and now I'm calling the function again but this doesn't seem to select the row first before displaying the Inputbox again.
Can anyone help? Please?
Thank you in advance.