Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Syncronise Form and Report Recordsource on Print Report action

Posted on 2014-03-20
3
Medium Priority
?
614 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

604 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