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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

listbox selection by letters

Status
Not open for further replies.

DUF

Technical User
Mar 10, 2001
107
IE
Hi,
On a form I have one listbox which to bound to a query from tblSuppliers, One subform which will display the deatils of then supplier which everone is selected in the listbox.
I also have a command button for every leter of the alphaped.
What I want is that when any of the command buttons is pressed the listbox will jump to the first occourcense of the letter, ie pressing the cmdK button the listbox will select the first name which starts with K and the subform will display the details of the first name.

Can any one help?????? please or point me in the right direction

thanks
Duf
 
Hi

Something like:

Sub SetListBox(strCommandLetter AS String)
Dim i as Long

For i = 0 To lstMyListBox.ListCount - 1
If Left(lstMyListBox.Column(i,0),1) = strCommandLetter Then
lstMyListBox.ListIndex = i
i = lstMyListBox.ListCount + 1
End If
Next i
called from the OnClick event of each comand button, passing the id of Command Button (eg A, B etc), you could probably do this by passing Left(cmdButton.caption,1), depending on what you have as the caption,

Using your own control names of course
End Sub

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top