List Box: goto a row

J

Jim Bunton

Access 97
Have a list box
Can find which row I'm on with
ListboxName.ListIndex

Now
?? How can I get back there, i.e. move to s specified row ??

ListboxName.ListIndex = aNumber
gives error - 7777 you've used the ListIndex property incorrectly

I guess it's read only!
 
T

Tom Wickerath

Hi Jim,

Try setting focus to the control first. The following works for me in Access
2003 (my listbox rowsource contains more than 11 rows--this property is zero
based, so setting it to 10 in the example below selects the 11th record). I
cannot say if this will work in Access 97, as I no longer have that version
installed:

Option Compare Database
Option Explicit

Private Sub cmdTestListbox_Click()
MsgBox lboSuppliers.ListIndex
Me.lboSuppliers.SetFocus
lboSuppliers.ListIndex = 10
End Sub

If you have the multiselect property set, then the first line of code,
MsgBox lboSuppliers.ListIndex, returns the highest index number.


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top