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

SetFocus

Status
Not open for further replies.

illini

Technical User
Aug 2, 2002
89
FR
Using VBA, how can you set the focus on a specific entry within a listbox?

I would appreciate any input. -illini
 
Hi Illini!

If you want to highlight the first entry you would use:

Me!YourListBox.Selected(0) = True

You would increment the 0 by 1 for the next entry and so on. If you are not sure where the entry will be, but you know what it will say then you can use the following:

Dim intRow As Integer

For intRow = 0 to Me!YourListBox.ListCount - 1
If Me!YourListBox.Column(0, intRow) = "Whatever" Then
Me!YourListBox.Selected(intRow) = True
Exit For
End If
Next intRow

hth
Jeff Bridgham
bridgham@purdue.edu
 
Jeff,

I appreciate the input. I'm using the following line...

Me!YourListBox.Selected(x) = True

This highlights great, but when I try to arrow down on the listbox, the focus begins with the first entry. How can I set the focus mid-way in a listbox? -illini
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top