Listbox value

G

Guest

I have an unbound listbox on my form that I want the value passed on to a
Visual Basic routine automatically. I found this code in the threads and the
listbox is selected but the value passed is still NULL when checking the
routine's values.

Me.List1.Selected(0) = True

In the same routine or another I want to test for

If Temp = List1 Then ...

The correct value of the listbox shows on the form but no value is passed to
VB. If I click on the listbox with the mouse then the correct value is passed
to VB even if the record is changed. The listbox will be hidden in normal
use so has to be automatic.
Any help would be appreciated. I couldn't find any example to solve that.
 
D

Dan Artuso

Hi,
Yes, the answer to this problem is not very intuitive.
Try this (assuming you have column heads set to no):

MeList1.Selected(1) = True
MsgBox Me.List0.ItemData(Me.List1.ListIndex)
 
G

Guest

Thanks Dan. I modified what you gave me to

If Temp = Me.List1.ItemData(Me.List1.ListIndex) Then

and the value is there. Works great now. This will work on all the forms
I'm modifying. Your input is greatly appreciated.
 

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