Listbox Referencing

DevastatioN

Registered User.
Local time
Today, 07:57
Joined
Nov 21, 2007
Messages
242
Hello,

Weird thing with Listboxes here... I have buttons that allow me to navigate up and down a listbox, the following:

For i = 0 To lstTest.ListCount - 2
If lstTest.Selected(i) And move = False Then
lstTest.Selected(i) = False
lstTest.Selected(i + 1) = True
move = True
End If
Next

I also have a button that is supposed to open a form filtered based on the listbox with the follownig:

stLinkCriteria = "[Blah]=" & Me![lstTest]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Let's say I have a list box with the numbers 1 through 20.

If I click on 5 and click "Open" the form Opens for record 5... if I click 8, press open the form opens for record 8... however if I click 8, and then use my scroll buttons to navigate down to record 10, when I click open, record 8 appears.

Even though the listbox appears to have selected the correct thing based on my code and appearence, it is still storing the last mouse clicked value.

Any ideas?
 
Fixed it myself... forgot a line of code that is important it seems.

ItemData needs to also be set to the correct value, so the code now is:

For i = 0 To lstTest.ListCount - 2
If lstTest.Selected(i) And move = False Then
lstTest.Selected(i + 1) = True
lstTest = lstTest.ItemData(i + 1)
move = True
End If
Next

This is what I was playing around with, if anyone was interested in seeing it.
 

Attachments

Users who are viewing this thread

Back
Top Bottom