Solved

Syncronise Form and Report Recordsource on Print Report action

Posted on 2014-03-20
3
526 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…

705 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now