E
Erna Henderson
I have a form with a multi select list box, two date range
boxes, and a preview report command button. I want to
pass the one or more items selected in the multi select
list box along with the from and to date ranges to my
query which opens the report. Here is my code to get the
names from the listbox concatenated into the variable
strSql. How do I get the strSql information to my query?
Any help would be appreciated. Thank you.
Private Sub PreviewReport_Click()
On Error GoTo Err_PreviewReport_Click
Dim frm As Form, ctl As Control
Dim varItem As Variant
Dim strSql As String
Dim stDocName As String
Set frm = Form!frmAgentSelectionForm
Set ctl = frm!MultiSelectListBox
strSql = "Select * from Customer Service where
[Rep]="
For Each varItem In ctl.ItemsSelected
strSql = strSql & ctl.ItemData(varItem) & " OR
[Rep]="
Next varItem
strSql = Left$(strSql, Len(strSql) - 12)
stDocName = "Agent Average Report"
DoCmd.OpenReport stDocName, acPreview
Exit_PreviewReport_Click:
Exit Sub
Err_PreviewReport_Click:
MsgBox Err.Description
Resume Exit_PreviewReport_Click
End Sub
boxes, and a preview report command button. I want to
pass the one or more items selected in the multi select
list box along with the from and to date ranges to my
query which opens the report. Here is my code to get the
names from the listbox concatenated into the variable
strSql. How do I get the strSql information to my query?
Any help would be appreciated. Thank you.
Private Sub PreviewReport_Click()
On Error GoTo Err_PreviewReport_Click
Dim frm As Form, ctl As Control
Dim varItem As Variant
Dim strSql As String
Dim stDocName As String
Set frm = Form!frmAgentSelectionForm
Set ctl = frm!MultiSelectListBox
strSql = "Select * from Customer Service where
[Rep]="
For Each varItem In ctl.ItemsSelected
strSql = strSql & ctl.ItemData(varItem) & " OR
[Rep]="
Next varItem
strSql = Left$(strSql, Len(strSql) - 12)
stDocName = "Agent Average Report"
DoCmd.OpenReport stDocName, acPreview
Exit_PreviewReport_Click:
Exit Sub
Err_PreviewReport_Click:
MsgBox Err.Description
Resume Exit_PreviewReport_Click
End Sub