Report based on form filter?

C

Cam

Hello,

I have a form with Multiple fields filter based on and event procedure where
I can filter multiple combo fields. I would like to print a report after the
filtered fields, but not sure how to like what is the control source etc..
Any help is appreciated.

Here is my sample form filter event procedure.

Private Sub cmdFilter_Click()

Dim strWhere As String
Dim lngLen As Long

If Not IsNull(Me.cboMach) Then
strWhere = strWhere & "([Mach] = '" & Me.cboMach & "') AND "
End If

If Not IsNull(Me.cboOrd) Then
strWhere = strWhere & "([Ord] = '" & Me.cboOrd & "') AND "
End If

If Not IsNull(Me.cboWC) Then
strWhere = strWhere & "([WC] = '" & Me.cboWC & "') AND "
End If

If Not IsNull(Me.cboPart) Then
strWhere = strWhere & "([Part] = '" & Me.cboPart & "') AND "
End If

If Not IsNull(Me.cboShift) Then
strWhere = strWhere & "([Shift] = " & Me.cboShift & ") 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
 
M

Marshall Barton

Cam said:
I have a form with Multiple fields filter based on and event procedure where
I can filter multiple combo fields. I would like to print a report after the
filtered fields, but not sure how to like what is the control source etc..
Any help is appreciated.

Here is my sample form filter event procedure.

Private Sub cmdFilter_Click()

Dim strWhere As String
Dim lngLen As Long

If Not IsNull(Me.cboMach) Then
strWhere = strWhere & "([Mach] = '" & Me.cboMach & "') AND "
End If

If Not IsNull(Me.cboOrd) Then
strWhere = strWhere & "([Ord] = '" & Me.cboOrd & "') AND "
End If

If Not IsNull(Me.cboWC) Then
strWhere = strWhere & "([WC] = '" & Me.cboWC & "') AND "
End If

If Not IsNull(Me.cboPart) Then
strWhere = strWhere & "([Part] = '" & Me.cboPart & "') AND "
End If

If Not IsNull(Me.cboShift) Then
strWhere = strWhere & "([Shift] = " & Me.cboShift & ") 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


You probably should use a button to run the report.
Assuming the report's record source has the fields that may
be filtered, the code would be like:

DoCmd.OpenReport "name of report", , , Me.Filter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top