Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / July 2006

Tip: Looking for answers? Try searching our database.

accessing a second column of a multiple select list box...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Brad Pears - 07 Jul 2006 21:25 GMT
I have a list box where the row source is an SQL "select" statment of two
columns from a table - the first column being an ID and the second column
being the ID description that the user is selecting. The user can select
multiple items in the listbox. I can access the ID portion of the listbox
(the 1st column) no probs using the mylstbox.itemdata(i) BUT how do I access
the 2nd column of a selected item using the .columns(x) format?? I tried
many different syntaxes and none seemed to work...

Example...
Table: Test
Fields: 2
FieldNames: "First" and "Last"
table data...
First              Last
"Brad"             "Pears"
"Terry"            "Corbet"
"Paul"            "Madden"

ListBox row source: "select * from TEST"
Columns:2
Bound Column: 1
Col Widths:2.54;2.54

The user selects items from the listbox and then the following code runs...

Private Sub Command0_Click()
Dim i As Variant
For Each i In mylstbox.ItemsSelected
  ' Displays the data in the first column only (i.e. the first names)
   MsgBox mylstbox.ItemData(i)
   ' Now I would also like to display the data in column 2 (the last names)
   msgbox ?????????
   Next i
End Sub

Any help would be most appreciated!

Thanks,

Brad
Wayne Morgan - 07 Jul 2006 22:57 GMT
Try

MyListbox.Column(1, i)

Both indexes are zero based, so 1 is the second column. The ItemData index
is also zero based, so just using "i" should work.

Signature

Wayne Morgan
MS Access MVP

>I have a list box where the row source is an SQL "select" statment of two
>columns from a table - the first column being an ID and the second column
[quoted text clipped - 38 lines]
>
> Brad
Brad Pears - 10 Jul 2006 16:04 GMT
Works like a top!!!  I completely missed the ability to specify the index
portion after the column number when using the .column method...

Thanks for that!

Brad

> Try
>
[quoted text clipped - 45 lines]
>>
>> Brad
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.