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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading the values from a multi-select listbox 1

Status
Not open for further replies.

whatisahandle

Programmer
Jul 26, 2001
18
CA
Hi,

Could someone kindly show me the way to read the values from a multiselect listbox in Access ? The access help files are not too helpful on this ...

Thanx

Chris
 
Hi Chris!

Try using this code:

Dim varRowNumber As Variant

For Each varRowNumber In YourListBox.ItemsSelected
Do your stuff here. You access the data using
YourListBox.Column(ColumnNumber, varRowNumber)
Next varRowNumber

This will loop through the items selected. You need to put in the actual column number you are interested in, usually it is 0(1st column). If you have more than one column that you are interested in, then you can nest two loops:

Dim varRowNumber As Variant
Dim ColumnNumber As Integer

For Each varRowNumber In YourListBox.ItemsSelected
For ColumnNumber = 0 To NumberOfColumns
Do your stuff here. You access the data using
YourListBox.Column(ColumnNumber, varRowNumber)
Next ColumnNumber
Next varRowNumber

hth Jeff Bridgham
bridgham@purdue.edu
 
Can you give a few details about how you are planning to use the listbox? I use a multiselect list box to allow users to select multiple criteria for filtering reports. So I use code to put the chosen items in a filter for the report then some other code to put this in a form I can use to quote in the report header. If you need samples of this I can post my code but you may have a different need.
ie to filter a report I open it
DoCmd.openReport "report", acViewPreview, , GetCriteria()

This calls the following procedure the listbox is called origin and it provides the field DCR_txt_Origin in this example
Private Function GetCriteria() As String
Dim stDocCriteria As String
Dim VarItm As Variant
Dim StrItm As String
For Each VarItm In Origin.ItemsSelected

stDocCriteria = stDocCriteria & "[DCR_txt_Origin] = """ & Origin.Column(0, VarItm) & """ OR "

Next

If stDocCriteria <> &quot;&quot; Then
stDocCriteria = Left(stDocCriteria, Len(stDocCriteria) - 4)
Else
stDocCriteria = &quot;True&quot;
End If
GetCriteria = stDocCriteria

End Function
I hope this helps

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top