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

Bit of code for a multiselect list box please...

Status
Not open for further replies.

MajorChaos

Technical User
Apr 21, 2001
8
US
I need a bit of code for a multiselect list box please.
also show me how to implement it. i.e. (function, sub, etc.) Im kinda new at this. Its the last chunk I need to get things going on a special form... ( my first!) so details please.. LOL
 
This example uses the results of a multi-select listbox to set the criteria for a report. Listbox contains the ID Field and the LastName Field. It might get you started in the right direction.

Private Sub cmdViewReport_Click()
Dim strCriteria As String, strLng As Long, strField As String
Dim lngItem As Long
Dim varItem As Variant
strField = "[LastName]= "

For Each varItem In lstNames.ItemsSelected()
lngItem = varItem
strCriteria = strCriteria & " Or " & strField & Chr(39) & lstNames.Column(1, lngItem) & Chr(39)
Next

strLng = Len(strCriteria)
strCriteria = Right(strCriteria, strLng - 4)

MsgBox "Criteria is : " & strCriteria

DoCmd.OpenReport "rptEmployees", acViewPreview, , strCriteria
End Sub

PaulF
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top