I am trying to filter a report based on combobox selections. When a value is welected for a combobox, that value is passed to the query, but when a combobox value is not shosen, it is supposed to pass a "like '*'" but it isn't. Can someone please have a look at this code and tell me where I am going wrong? OR - if you have a better suggestion, please let me know.
Thanks, PDUNCAN
Memphis, TN - USA
When I die, I want to die like my grandfather-- who died peacefully in
his sleep. Not screaming like all the passengers in his car.
Code:
Private Sub cmdApplyFilter_Click()
Dim strController As String
Dim strActivity As String
Dim strLocation As String
Dim strStartDate As String
Dim strEndDate As String
Dim strFilter As String
Dim stDocName As String
stDocName = "rptActivity"
If SysCmd(acSysCmdGetObjectState, acReport, stDocName) <> acObjStateOpen Then
MsgBox "You must have the report open first." & vbCrLf & "Press the 'Open Report' button", , "Notice"
Exit Sub
End If
'Build criteria string for Controller field
If IsNull(Me!cboController.Value) Then
strController = "Like '*'"
Else
strController = "='" & Me!cboController.Value & "'"
End If
'Build criteria string for Activity field
If IsNull(Me!cboActivity.Value) Then
strActivity = "Like '*'"
Else
strActivity = "='" & Me!cboActivity.Value & "'"
End If
'Build criteria string for Location field
If IsNull(Me!cboLocation.Value) Then
strLocation = "Like '*'"
Else
strLocation = "='" & Me!cboLocation.Value & "'"
End If
'Build criteria string for Start Date field
'Build criteria string for End Date field
'Combine criteria strings into where clause for the filter
strFilter = "Controller " & strController & " AND Event " & strActivity
MsgBox strFilter
With Reports![rptActivity]
.Filter = strFilter
.FilterOn = True
End With
End Sub
Thanks, PDUNCAN
Memphis, TN - USA
When I die, I want to die like my grandfather-- who died peacefully in
his sleep. Not screaming like all the passengers in his car.