Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get Listbox Value rather than location number 1

Status
Not open for further replies.

mxp346

MIS
Apr 27, 2002
50
0
0
US
I have the below code so far. The problem is that the variants are being populated with a number equal to the location in their respective listbox. I want the variant to equal the actual value. I'm not sure if this will have an impact on how the correct code is written but the values in the listboxes do change based on other selections made in the form.

Code:
Dim lbRoles As ListBox
Dim lbOrganizations As ListBox
Dim varOrganization As Variant
Dim varRole As Variant
        
For Each varOrganization In Me.lbOrganizations.ItemsSelected
  For Each varRole In Me.lbRoles.ItemsSelected
         DoCmd.RunSQL "INSERT INTO ....               
   Next varRole
Next varOrganization


Thank you very much for any help.

 
Hi
Maybe:
[tt]For Each varRole In Me.lbRoles.ItemsSelected
... Me.lbRoles.ItemData(varRole)[/tt]
 
How are ya mxp346 . . . . .

Your problem is:
Microsoft said:
[blue]The ItemsSelected collection is unlike other collections in that it is a collection of Variants rather than of objects. [purple]Each Variant is an integer index referring to a selected row in a list box or combo box.[/purple][/blue]
To reference fields in that row, you need something like:
Code:
[blue]   Me!ListboxName.Column(ColumnNum, varOrganization)[/blue]
. . . to access the actual value!

Your thoughts!

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top