I have a button with an 'On Click' [Event Procedure] to filter the form, it is a multiple search criteria filter (see code below).
And yes, I want the report to apply the same filter. I was envisioning a third button on my form 'print filtered records' that would open the report, apply the filter and go to print preview.
the Apply filter code:
Private Sub ApplyFilter_Click()
Dim strWhere As String
Dim lngLen As Long
Const conJetDate = "\#mm\/dd\/yyyy\#"
If Not IsNull(Me.txtFilterPermitNum) Then
strWhere = strWhere & "([Permit_Num] Like ""*" & Me.txtFilterPermitNum & "*"") AND "
End If
If Not IsNull(Me.txtFilterPermitType) Then
strWhere = strWhere & "([Permit_Type] = """ & Me.txtFilterPermitType & """) AND "
End If
If Not IsNull(Me.txtFilterPermitDesc) Then
strWhere = strWhere & "([Permit_Desc] Like ""*" & Me.txtFilterPermitDesc & "*"") AND "
End If
If Not IsNull(Me.txtFilterStartDate) Then
strWhere = strWhere & "([Permit_AppRecDate] >= " & Format(Me.txtFilterStartDate, conJetDate) & ") AND "
End If
If Not IsNull(Me.txtFilterEndDate) Then
strWhere = strWhere & "([Permit_AppRecDate] < " & Format(Me.txtFilterEndDate, conJetDate) & ") AND "
End If
If Not IsNull(Me.txtFilterEng) Then
strWhere = strWhere & "([EngInit] Like ""*" & Me.txtFilterEng & "*"") AND "
End If
If Not IsNull(Me.txtFilterAPN) Then
strWhere = strWhere & "([Prop_APN] Like ""*" & Me.txtFilterAPN & "*"") AND "
End If
If Not IsNull(Me.txtFilterStNum) Then
strWhere = strWhere & "([Prop_StNum] = """ & Me.txtFilterStNum & """) AND "
End If
If Not IsNull(Me.txtFilterStreet) Then
strWhere = strWhere & "([Prop_Street] Like ""*" & Me.txtFilterStreet & "*"") AND "
End If
If Not IsNull(Me.txtFilterCity) Then
strWhere = strWhere & "([Prop_City] = """ & Me.txtFilterCity & """) AND "
End If
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then
MsgBox "No criteria", vbInformation, "Nothing to do."
Else
strWhere = Left$(strWhere, lngLen)
Me.Filter = strWhere
Me.FilterOn = True
End If
End Sub