?
Solved

Syncronise Form and Report Recordsource on Print Report action

Posted on 2014-03-20
3
Medium Priority
?
607 Views
Last Modified: 2014-03-22
I use the code below in the Click event on my form to set the report filter. I now also want to set the recordsource of the report to the same as the form. How should I alter my code.

Private Sub cmdOpenReport_Click()       'I click on Print button on my form

        Me.Requery
        DoCmd.OpenReport "rptqrytblBuilt", A_PREVIEW, , Me.Filter

End Sub
0
Comment
Question by:Fritz Paul
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 2000 total points
ID: 39943971
Your code simply filters the report using the Form's current filter (if any). If the Form and Report are based on the same basic recordsource that would work, but if not you'd have to do more work to handle this.

That said, if you really want to set the Report's Recordsource, you have to do that from the REport. In the Load event, do something like this:

Me.Recordsource = Forms!YourForm.Recordsource

That would set the report to the same Recordsource, and you can still include your Filter criteria, or you could take the above method a step further:

Me.Recordsource = Forms!YourForm.Recordsource
Me.Filter = Forms!YourForm.Filter
Me.FilterOn = True
0
 

Author Closing Comment

by:Fritz Paul
ID: 39944393
This does not work on On Load when I get a message

"You can't Set the Record Source property in print preview or after printing has started."

But it work on On Open.

I wonder why
0
 
LVL 85
ID: 39947674
But it work on On Open.
Sorry about that - the Open event is the correct event to do this. By the time the Load event fires in a report, the source is already loaded and you cannot change it.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question