I’m a novice with Access so would be grateful for some guidance please.
I’m currently designing a database and have the following issue:
I have an ‘Unbound’ Combo Box and an ‘Unbound’ List Box which I’m using to create a report. Basically the user can select numerous ‘part numbers’ from the Combo Box (which is sourced from a table) which can then be (when selected by the user) added to a List Box. The user can then select the ‘part numbers’ that appear in the list box to generate a report. This works well with a code I got from ‘PBaldy’, however the list box shows the ‘ID’ number. What I want to show in the list box is the ‘Part Number’ not its ‘ID’ number and for it to generate a report from there. I’ve managed to get the ‘part number’ into the list box however the report doesn’t recognise my command and appears blank. A majority of the part numbers are numeric however there are some that contain letters too.
The code I have on the ‘Open Report’ command button is:
Private Sub Command25_Click()
On Error GoTo Err_cmdOpenReport_Click
Dim strWhere As String
Dim ctl As Control
Dim varItem As Variant
'make sure a selection has been made
If Me.MyList.ItemsSelected.Count = 0 Then
Exit Sub
End If
'add selected values to string
Set ctl = Me.MyList
For Each varItem In ctl.ItemsSelected
strWhere = strWhere & ctl.ItemData(varItem) & ","
Next varItem
'trim trailing comma
strWhere = Left(strWhere, Len(strWhere) - 1)
'open the report, restricted to the selected items
DoCmd.OpenReport "rptSearch", acViewReport, , "ID IN(" & strWhere & ")"
Exit_cmdOpenReport_Click:
Exit Sub
Err_cmdOpenReport_Click:
MsgBox Err.Description
Resume Exit_cmdOpenReport_Click
End Sub
Help with the above would be most appreciated.
Thank you.