Assigning variable to listbox value

latex88

Registered User.
Local time
Today, 07:06
Joined
Jul 10, 2003
Messages
198
This seems simple, but I'm getting error message. See attached. I'm trying to assign a variable to the value based on a selected item in a list box. I believe this is called unbounded list because I listed in the row source as "1,2,3,4...". What I have is below...

Private Sub myListBox_Click ()

Dim X As Integer
X = Me.myListBox.Selected
MsgBox X

End Sub
 

Attachments

  • Listbox Error Message.jpg
    Listbox Error Message.jpg
    59.5 KB · Views: 212
Try;
Code:
Private Sub myListBox_Click ()

Dim X As Integer
X = Me.myListBox.Column([B][COLOR="Red"]x[/COLOR][/B])
MsgBox X

End Sub

Where x is the number of the column you wish to return. Rememeber that the columns in a combo or List box are numbered from zero on up. So if you just want to know the value in the first columns use;
Code:
X = Me.myListBox.Column(0)
or even simpler;
Code:
X = Me.myListBox
 
Try;
Code:
Private Sub myListBox_Click ()

Dim X As Integer
X = Me.myListBox.Column([B][COLOR="Red"]x[/COLOR][/B])
MsgBox X

End Sub

Where x is the number of the column you wish to return. Rememeber that the columns in a combo or List box are numbered from zero on up. So if you just want to know the value in the first columns use;
Code:
X = Me.myListBox.Column(0)
or even simpler;
Code:
X = Me.myListBox

Thank you John for your input. I still get the same error message. I'm using Access 2010. Does this error have to do with Reference or something? I'm totally clueless what all those References mean. When I go to Tools, References, I see the following checked and in that priority order.

* Visual Basic For Applications
* Microsoft Access 14.0 Object Library
* OLE Automation
* Microsoft Office 14.0 Access database engine Object Library
 

Users who are viewing this thread

Back
Top Bottom