I have been struggling for days to achieve this simple procedure.
I want to be able to print/preview a report based on the selection made from a multiselect List Box. I've tried using some of the code sample from this forum
but can't quite manage to get it to work. The varItem seems to represent the row number of the ListBox items rather than the CID value in the query.
What do I need to change or add for the report to pickup the selected company.
Private Sub Form_Load()
'Fill the listbox using a saved query.
Me.LstFindings.RowSource = "AllCompany"
End Sub
Private Sub Select_Click()
Dim frm As Form, ctl As Control
Dim varItem As Variant
Dim strSQL As String
Set frm = Forms!frmcomp
Set ctl = frm!LstFindings
strSQL = "Select * from AllCompany where [CID]="
'Assuming long [EmpID] is the bound field in lb
'enumerate selected items and
'concatenate to strSQL
For Each varItem In ctl.ItemsSelected
strSQL = strSQL & ctl.ItemData(varItem) & " OR [CID]="
Next varItem
'Trim the end of strSQL
strSQL = Left(strSQL, Len(strSQL) - 10)
'This statement doesn't work. Report Runtime error
DoCmd.RunSQL strSQL
End Sub
I want to be able to print/preview a report based on the selection made from a multiselect List Box. I've tried using some of the code sample from this forum
but can't quite manage to get it to work. The varItem seems to represent the row number of the ListBox items rather than the CID value in the query.
What do I need to change or add for the report to pickup the selected company.
Private Sub Form_Load()
'Fill the listbox using a saved query.
Me.LstFindings.RowSource = "AllCompany"
End Sub
Private Sub Select_Click()
Dim frm As Form, ctl As Control
Dim varItem As Variant
Dim strSQL As String
Set frm = Forms!frmcomp
Set ctl = frm!LstFindings
strSQL = "Select * from AllCompany where [CID]="
'Assuming long [EmpID] is the bound field in lb
'enumerate selected items and
'concatenate to strSQL
For Each varItem In ctl.ItemsSelected
strSQL = strSQL & ctl.ItemData(varItem) & " OR [CID]="
Next varItem
'Trim the end of strSQL
strSQL = Left(strSQL, Len(strSQL) - 10)
'This statement doesn't work. Report Runtime error

DoCmd.RunSQL strSQL
End Sub