Dim cFound As Boolean
Dim intIndex As Integer
bFound = False
intIndex = 0
Do While Not cFound And intIndex < ListBox1.ListCount
If UCase(Left(ListBox1.List(intIndex), Len(tb7.Text))) = UCase(tb7.Text) Then
ListBox1.ListIndex = intIndex
cFound = True
End If
intIndex = intIndex + 1
Loop
The above code is a snippet that I have in my program. It works perfectly for what I need the only problem with it is the if statement. It is set up to search my listbox for a name and then highlight the name but it has no "safety" if the name isn't found (i.e. flashes an error). I tried to put an Else statement in the code so if a name wasn't found it would flash a message and it worked fine, but it kept flashing the message even if a name was found. I hope this isn't too confusing. Any help would be greatly appreciated.
Dim intIndex As Integer
bFound = False
intIndex = 0
Do While Not cFound And intIndex < ListBox1.ListCount
If UCase(Left(ListBox1.List(intIndex), Len(tb7.Text))) = UCase(tb7.Text) Then
ListBox1.ListIndex = intIndex
cFound = True
End If
intIndex = intIndex + 1
Loop
The above code is a snippet that I have in my program. It works perfectly for what I need the only problem with it is the if statement. It is set up to search my listbox for a name and then highlight the name but it has no "safety" if the name isn't found (i.e. flashes an error). I tried to put an Else statement in the code so if a name wasn't found it would flash a message and it worked fine, but it kept flashing the message even if a name was found. I hope this isn't too confusing. Any help would be greatly appreciated.