Listbox Navigation

D

DS

How do you refer to a Listbox on a Main Form? I built Navigation
Buttons with the wizard but I can't get them to move to Next or Previous
record in the Listbox.
Thanks
DS
 
D

Dan Artuso

Hi,
The wizard buttons will move to the next or previous record of the recordset your
form is bound to. In turn, any bound control on the form will display the value from the
field it is bound to.
Your list box must be unbound.
You refer to the listbox like this:

Me.yourListbox 'if the code is running from the form itself

or

Forms!yourForm!yourListbox 'if the code is running outside of the form
 
D

DS

Dan said:
Hi,
The wizard buttons will move to the next or previous record of the recordset your
form is bound to. In turn, any bound control on the form will display the value from the
field it is bound to.
Your list box must be unbound.
You refer to the listbox like this:

Me.yourListbox 'if the code is running from the form itself

or

Forms!yourForm!yourListbox 'if the code is running outside of the form
Your right, the listbox is unbound. So how do I apply Navigation
Buttons to an Unbound ListBox?
Thanks
DS
 
D

DS

Stephen said:
Go to Form properties and set the Key Preview to Yes.

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

Select Case KeyCode

Case vbKeyDown
Me.List2 = Me.List2.ItemData(Me.List2.ListIndex + 1)
KeyCode = 0


Case vbKeyUp
Me.List2 = Me.List2.ItemData(Me.List2.ListIndex - 1)
KeyCode = 0

Case Else
End Select

End Sub

Tthe above code is for a ListBox named List2. Change the name to reflect
your ListBox. Also this is set to work with a ListBox WITHOUT Column
Headers turned on. You'll have to adjust it if you use Column Headers.
Finally the Arrow Keys are sent to oblivion with the Line KeyCode =0.


--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.




recordset your


display the value from the
Thaks, Ill give it a try.
DS
 
Top