Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listbox Positioning

Status
Not open for further replies.

DaveL

Programmer
Jun 8, 2000
40
US
Is there a way to position in a listbox using more than one character... in other words, I would like to start typing out a word and have the listbox positioned based on ALL of the characters that have been typed, not just the first character... similar to the way it works for a combo box.
 
Yes. I have a list box I wrote something like this for. Create a text box above the list box for the user to type in. In the On Change event for the text box put this code.

Private Sub txtMyTextBox_Change()
'clear the items selected in the listbox if _
the user enters something into the textbox
Dim var As Variant
For Each var In Me.lstGroup.ItemsSelected
Me.lstGroup.Selected(var) = False
Next var

strItem = txtNewGroup.Text
For itemIndex = 0 To Me.lstGroup.ListCount - 1

If Me.lstGroup.ItemData(itemIndex) Like strItem & "*" Then
Me.lstGroup.Selected(itemIndex) = True
Exit For
End If
Next itemIndex
End Sub

You have to dim two varibles at the form level called itemIndex as Integer and strItem as String.

Hope that helps.

ProDev, Builders of Affordable Software Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 
Thanks Lonnie!

I used your idea with a minor change and it works great.

I added a text box to the form and then in the OnChange event for the text box I modify the RowSource and Requery the ListBox. Works exactly the way I need it to.

Thanks again for the nudge in the right direction!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top