Listbox Navigation

  • Thread starter Thread starter DS
  • Start date Start date
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
 
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
 
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
 
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.
 
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
 

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

Similar Threads

Requery listbox 1
Listbox Click does nothing 2
Access Cannot select items in listbox 1
Opening Form to specified record 1
Listbox query 3
Faster DCount or Query 6
Listbox problem 3
ListBox help 1

Back
Top