Solved

Syncronise Form and Report Recordsource on Print Report action

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
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…

717 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