K
Kenny G
Hello,
Currently I have a multiselect list box that does not allow me to select
anything from the box. This listbox is supposed to let me select from the
listbox to print a report. The report is related to a query. Below is the
code for the command button.
Private Sub cmdLocationandStandardsReport_Click()
Dim ctl As Control
Dim var As Variant
Dim strSQL As String
Dim strIdentifier As String
Set ctl = Me.lstSiteLocation
strIdentifier = "Location = "
'check for selection
If ctl.ItemsSelected.Count = 0 Then
MsgBox "Please Make A Selection or Selections.", vbOKOnly, "Error"
Exit Sub
End If
'cycle through selected items
'to build SQL WHERE expression
For Each var In ctl.ItemsSelected
strSQL = strSQL & strIdentifier & ctl.ItemData(var) & " OR "
'Added Next
Next
'Test right 3 characters for " OR ", remove if found
If Right$(strSQL, 3) = " OR " Then
strSQL = Left$(strSQL, Len(strSQL) - 3)
End If
DoCmd.OpenReport "Location and Standards Report", acViewPreview, ,
strSQL
End Sub
I have placed in the report Data Tab I have as the record source
"qLocationsandStandards" for the filter I have (Location = Surgical Pavilion
OR Location = Child Life)
I appreciate your assistance.
Kenny G
Currently I have a multiselect list box that does not allow me to select
anything from the box. This listbox is supposed to let me select from the
listbox to print a report. The report is related to a query. Below is the
code for the command button.
Private Sub cmdLocationandStandardsReport_Click()
Dim ctl As Control
Dim var As Variant
Dim strSQL As String
Dim strIdentifier As String
Set ctl = Me.lstSiteLocation
strIdentifier = "Location = "
'check for selection
If ctl.ItemsSelected.Count = 0 Then
MsgBox "Please Make A Selection or Selections.", vbOKOnly, "Error"
Exit Sub
End If
'cycle through selected items
'to build SQL WHERE expression
For Each var In ctl.ItemsSelected
strSQL = strSQL & strIdentifier & ctl.ItemData(var) & " OR "
'Added Next
Next
'Test right 3 characters for " OR ", remove if found
If Right$(strSQL, 3) = " OR " Then
strSQL = Left$(strSQL, Len(strSQL) - 3)
End If
DoCmd.OpenReport "Location and Standards Report", acViewPreview, ,
strSQL
End Sub
I have placed in the report Data Tab I have as the record source
"qLocationsandStandards" for the filter I have (Location = Surgical Pavilion
OR Location = Child Life)
I appreciate your assistance.
Kenny G