How to apply the form filter on the report?

P

Pietro

Hi,

I have a report that's based on the same query of a form, so i can
select some search criteria on the form and press on a button to open the
report with the same criteria selected on a form.
It happens that sometimes users filter the form by using a sort menu
that i created with the form,but when they open the report, it does not have
the same data as the report is not filtered.
My quetion is how to apply the form filter on the report?
 
P

Petr Danes

Hi Pietro,

In the code for the button which calls the report, use Me.Filter to get the
current active filter (also check Me.FilterOn, to determine if the filter is
active) then include the filter text as the Where condition in the call
which opens the report, like this:

If Me.FilterOn Then
fltrtxt = Me.Filter
Else
fltrtxt = ""
End If

DoCmd.OpenReport "MyRpt", acViewNormal, , fltrtxt
' Note that text goes in the Where parameter,
' not the FilterName parameter.

Petr
 
P

Pietro

Thanx alot Petr,

Can we do the same with forms and subforms?

I tried, but catually inserting a subform in a continous form is not allowed.

Please advise
 
P

Petr Danes

You can call a form from a form, using DoCmd OpenForm, and the Where
parameter will work just as it does when you call a report, but an embedded
subform is handled differently.

You would set the filter property of either the main form, with:

Me.Filter = "some filter text"
Me.FilterOn = True

or of the subform with:

SubformControlName.Form.Filter = "some filter text"
SubformControlName.FilterOn = True

You're right, a continuous form cannot have embedded subforms. An embedded
subform may be continuous, but not a parent form.

Petr
 

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