- ROM
- CPU
- RAM
- GPU
Access 2003
Table columns:
Col 1 = Primary Key Record Identifier
col 2 =The NAME of of the Unique record
Example
10001 Product Name 1
10002 Product Name 2
I have a list box that is populated from a table.
I want to select multiple values from the list box, then record ALL the columns info selected in the list box in a log.
The first time through the For Each I can get the value for Column 1.
But the second [and subsequent] times through the loop, I can't access the CURRENT ITEMs second column.
Example in the CODE box below.
Here is what the results look like
10001 Product Name 1
10002 Product Name 1 [notice the first column is okay, the second still references Product ONE]
For each Row in the ListBox, I need to be able to get the "BoundColumn" value [10002] and the TEXT in the list "Product Name 2"
Any help would be appreciated!
Assuming its a 2 column list box and the value you seek is in the second column:
Me.ListBox.Column[1, varItem]
Should do the trick.
6 Replies
Assuming its a 2 column list box and the value you seek is in the second column:
Me.ListBox.Column[1, varItem]
Should do the trick.
Here is some code I use for getting the multiple values selected from a list box. I put them into a table and then use that table in a query.
You can reference the other column's in a combo box with the reference Me.ComboBox.Column[2] [just change the number to be whatever column you need]. I assume it is similar for a listbox but I have not tried to reference multi column listbox before.
kevinhuges2 thanks! I worked on that for hours and couldn't figure it out. It wasn't for not Googling! But nobody seemed to reference how to get that second column.
Tons of articles on how to iterate over the selected items, but nothing I could find on how to get that second column [not the bound column].
Thanks Again!
As kevinhuges2 pointed out, you need the Index of the Current Selected Item like this:
The magic sauce was in the second parameter to the Column property [1, varItem] That says "get the Column property for the currently referenced Item from the list of selected items in the For Each Loop. It's really odd to me that nobody seemed to mention this in any of the 20 or 30 posts I've read over the past few days about this.
I got ya now. I thought when you wanted multiple values, that you wanted multiple selected values from the list box and any other columns from the selected values. So then you could use a little bit of both. Glad you got your answer.
There are times when SO devolves into pedantic nonsense debates ... but heres one.
//stackoverflow.com/questions/4649000/retrieve-column-values-of-the-selected-row-of-a-multicolumn-access-listbox
This topic has been locked by an administrator and is no longer open for commenting.
To continue this discussion, please ask a new question.