Question listbox help

jaz1976

New member
Local time
Today, 09:24
Joined
Oct 4, 2012
Messages
5
Hey,

I need help with a listbox. I have a listbox that is populated with data from a table. I would like to use one of the columns data as the where clause of a sql string that will populate another form, how do I get the selected items column data that I need into a variable? This is in Access 2010 vba.
 
Try this..
Code:
yourVariable = Me.ListBoxName.Column(columnNumber, ListBoxName.ItemsSelected)
Listbox columns are zero based which means if you want data from 1st column you will use 0 not 1..
 
Ok, your code seems to work fine. I am getting the right data from the selected items column, but I don't know what I'm doing wrong with my code.

Code:
Private Sub btn_Review_Click()
    Dim temp_jobID As Control
    
    Set temp_jobID = Me.ls_JobsToCommitInfo.Column(0, ls_JobsToCommitInfo.ItemsSelected)
    Debug.Print temp_jobID
End Sub

I am getting "Object Required on the Set line. I need to be able to set this to something I can use. I tried to set is as a string as well.
 
TRY:
Change
Dim temp_jobID As Control
to
Dim temp_jobID As String
 
Why have you declared temp_jobID as control??
 
I have tried that, and I get a Compiler error, Object Required with the Sub highlighted and the variable temp_jobID highlighted.
Code:
[highlight]Private Sub btn_Review_Click()[/highlight]
    Dim temp_jobID As String
    
    Set [highlight][COLOR=RoyalBlue]temp_jobID[/COLOR][/highlight] = Me.ls_JobsToCommitInfo.Column(0, ls_JobsToCommitInfo.ItemsSelected)
    Debug.Print temp_jobID
End Sub
 
Okay, I am not sure why you had it declared as Control.. and String does not need the Set keyword.. just
Code:
temp_jobID = .....
 
Sorry about that, I didn't see that I had the set keyword on the variable when I had it defined as a string. It is working now. Thanks for the help.
 
Thanks for the help everyone. Now that I got the data that I want from the selected row, I have put it into a hidden textbox. How do I pass that to another form in the DoCmd.OpenForm. This other form needs to be populated with the data of the record selected in the last form, so the user can review the data before committing it to the database.
 

Users who are viewing this thread

Back
Top Bottom