Printing report based on filtered form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How would I go about print a report based on a form that has a filter set.
The form is based on a table.
 
Hi Cyberwolf,

use the string value of Me.Filter to populate the WHERE of DoCmd.OpenReport,
for example use this code on the button on the form which opens the report:

Dim strWhere As String
strWhere= Me.Filter
DoCmd.OpenReport "YourReportName", acViewPreview, , strWhere
 
When you open the report pass the form filter to the report using the
OpenArgs variable.

On the form with the filter create the following Sub:
Private Sub RunMyReport (strReportName As String)
DoCmd.OpenReport strReportName , acViewPreview, , , _
acWindowNormal, Me.Filter
End Sub

Have some control or mechanism on the form to call the sub such as:
RunMyReport "My Custom Report"

In the report's Open action use the following example:
Private Sub Report_Open(Cancel As Integer)
If Not Me.OpenArgs = "" Then
Me.Filter = Me.OpenArgs
Me.FilterOn = True
End If
End Sub

When the report opens, it will set it's filter to the form's filter.

I hope this helps.
 
That looks great, but I should have explained that the form default view is
datasheet, and I would like this done on a menu icon or item. Is this
possible so the user doesn't have to chenge to form view>

Thanks in advance
 
Create the following Function in a module:
Public Function RunMyReport (strReportName As String, strFormName As String)
DoCmd.OpenReport strReportName , acViewPreview, , , _
acWindowNormal, Application.Forms(strFormName).Filter
End Function

On your Menu Item's On Action Box enter the following:
=RunMyReport ("Your Report Name","Your Form Name")

In the report's Open action use the following example:
Private Sub Report_Open(Cancel As Integer)
If Not Me.OpenArgs = "" Then
Me.Filter = Me.OpenArgs
Me.FilterOn = True
End If
End Sub
 
So When I try to run it I get a method or data member not found error on the
me.openargs line in the reports on open action.

I noticed as I was typing it in that it didn't show as one of the arguments.
 
Back
Top