Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reports from Filter by Form 1

Status
Not open for further replies.

tinahowe

Technical User
May 10, 2002
8
GB
Is it possible to create reports from Filter by form - I have a large database with multi office choices - I might need to select a haulier which covers three different areas and would like to be able to filter by form and then run a report from it. Does this sound possible. Please excuse my lack of knowledge - I am knew to Access but learning fast.

Thanks

Tina
 
Yes, you can do this. However, how you do it depends partly on how similar the form's and report's record sources are.

As long as the report's record source contains all the fields that can possibly be used for filtering the form, it's pretty easy. In the report's Open event, you just copy the form's Filter property to the report's Filter property:
Code:
    Me.Filter = Forms![form name].Filter

This works because Filter By Form works by changing the form's Filter property to reflect how the records are filtered.

Note: A report in which you do this can only be opened without an error if the related form is already open. If you want the report to be openable separately, you'll need to add code to check whether the form is open before you copy its Filter property.

It would be very convenient to put a Print Report command button on the form. The button doesn't have to do anything but open the report. Rick Sprague
 
I have tried what you have suggested which made perfect sense - but I keep getting the error message - Me. macro not found?

What am I doing wrong.

Thanks

Tina
 
I assumed you were using VBA code--most professionals don't use macros. The Me reference only has meaning within a form's or report's module.

I guess this would be a SetValue action. Me.Filter would become Reports![report name].Filter in the Item box, and Forms![form name].Filter goes in the Expression box. Rick Sprague
 
Sorry me again, I apologise for my lack of ability, I am genuinely stuck with this. On reflection it made sense to use VBA - I created the following as mentioned. My form name is info - when I open the report now I get the message - unable to find form name info - I am totally confused. Could you please look at what I have done and let me have your comments. Thanks again.

Option Compare Database

Private Sub Report_Open(Cancel As Integer)
Me.Filter = Forms![info].Filter
End Sub
 
I have sorted the problem out, thanks for all your help.
 
Tina,

Did you have to change what I gave you? If my advice was wrong, please tell me, so I'll know better next time, and so others reading this thread will have the answer. Rick Sprague
 
Hi,
You can use this code only when 'info' is open.
Open the report with a button of info form.

reza.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top