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
Solved

Syncronise Form and Report Recordsource on Print Report action

Posted on 2014-03-20
3
592 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
  • 2
3 Comments
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 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 84
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

789 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