copy filter from Form to Report

J

Jesus Campos

Hi,

I have a form and a report with the same data. On the form I active very
times filters and I would like to pass it for report to print the same data
of the form.

To open the report I have

stDocName = "form_name"
If Me.FilterOn = True Then
DoCmd.OpenReport stDocName, acPreview, Me.Filter
Else
DoCmd.OpenReport stDocName, acPreview
End If

But it report an error. Anyone can help me?
Thanks.
 
A

Allen Browne

What error number is it? What does the error message say?

Open the Immediate Window (Ctrl+G), and enter:
? Forms![Form1].Filter
substituting the name of your form for Form1.
What result do you get?

Are there any combo boxes involved in the filter? In Access 2002 or 2003,
this can mess up the ability to use the the filter in a report, unless you
create a query as the source for the report and alias the lookup tables with
the same name that the combo uses for them in the form's Filter.
 
J

Jesus Campos

Ok, sorry!

I did what you said, I create a query and I use it on the report and for the
form, and now ,how I can copy the filter from the form to the report?


PS: If you want you can send me a email and I reply to you with the mdb.
 
A

Allen Browne

The first question was:
What error number do you get?
What does the error message say?
 
J

Jesus Campos

The first question was:
What error number do you get?
What does the error message say?

It's not an error, it's an input argument asking for:
"Lookup_id__[tablename].[field_name]"



Code of form button:

Dim stDocName As String
stDocName = "report_name"
If Me.FilterOn = True Then
DoCmd.OpenReport stDocName, acPreview, , Me.Filter
Else
DoCmd.OpenReport stDocName, acPreview
End If
 
A

Allen Browne

Okay, create a query, using any table(s) you need.
Add the table that the combo gets it records from.
In the upper pane of query design, right-click this table.
Set its Alias property so it matches exactly the name that the argument is
looking for.

Once the names match correctly, the form's query will work in the report as
well.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Jesus Campos said:
The first question was:
What error number do you get?
What does the error message say?

It's not an error, it's an input argument asking for:
"Lookup_id__[tablename].[field_name]"



Code of form button:

Dim stDocName As String
stDocName = "report_name"
If Me.FilterOn = True Then
DoCmd.OpenReport stDocName, acPreview, , Me.Filter
Else
DoCmd.OpenReport stDocName, acPreview
End If
 
J

Jesus Campos

It works, many thanks!


Allen Browne said:
Okay, create a query, using any table(s) you need.
Add the table that the combo gets it records from.
In the upper pane of query design, right-click this table.
Set its Alias property so it matches exactly the name that the argument is
looking for.

Once the names match correctly, the form's query will work in the report
as well.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Jesus Campos said:
The first question was:
What error number do you get?
What does the error message say?

It's not an error, it's an input argument asking for:
"Lookup_id__[tablename].[field_name]"



Code of form button:

Dim stDocName As String
stDocName = "report_name"
If Me.FilterOn = True Then
DoCmd.OpenReport stDocName, acPreview, , Me.Filter
Else
DoCmd.OpenReport stDocName, acPreview
End If
 

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