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

Can I pass a recordset to a report?

Posted on 2016-08-27
5
63 Views
Last Modified: 2016-09-01
I have a form with a subform which contains a list of transactions filtered in various ways, by a filter which I create in code and load into the Filter property of the subform, which works.

I have a report similar to the form which I want to be able to print from a command button on the form, to contain the same data.  I have tried saving the filter from the subform and loading it into the Filter property of the subreport, but Access gives a compile error.   (Property doesn't support the method).

Can I pass the recordset from the subform to the Source Object of the subreport?

Thanks in advance,

Clive
0
Comment
Question by:CRB1609
  • 2
  • 2
5 Comments
 
LVL 19

Accepted Solution

by:
crystal (strive4peace) - Microsoft MVP, Access earned 500 total points
ID: 41772920
here is code you can run to set the report filter before it is opened:
'------------------------------------ SetReportFilter
Sub SetReportFilter( _
   psReportName As String _
   , pvFilter As Variant)
'strive4peace
   'Save a filter to the specified report
   'You can do this before you send a report in an email message
   'You can use this to filter subreports instead of putting criteria in the recordset

   ' USEAGE:
   ' example: in code that processes reports for viewing, printing, or email
   ' SetReportFilter "MyReportname","someID=1000"
   ' SetReportFilter "MyAppointments","City='Denver' AND dt_appt=#9/18/16#"

   ' PARAMETERS:
   ' psReportName is the name of your report
   ' pvFilter is a valid filter string or null

   On Error GoTo Proc_Err

   '---------- declare variables
   Dim rpt As Report

   '---------- open design view of report in Hidden mode (> Access 2000)
   DoCmd.OpenReport psReportName, acViewDesign ', , , acHidden

   '---------- set object variable to report
   Set rpt = Reports(psReportName)

   '---------- set report filter and turn it on
   rpt.Filter = pvFilter
   rpt.FilterOn = IIf(Len(Nz(pvFilter, "")) > 0, True, False)

   '---------- Save and Close report
   DoCmd.Close acReport, psReportName, acSaveYes

Proc_Exit:
   '----------  Release object variable
   Set rpt = Nothing
   Exit Sub

Proc_Err:
   Resume Next

   MsgBox Err.Description, , "ERROR " & Err.Number & "  SetReportFilter"
   'press F8 to step thru code and fix problem
   Resume Proc_Exit

   'if you want to single-step code to find error, CTRL-Break at MsgBox
   'then set this to be the next statement
   Resume

End Sub

Open in new window

0
 

Author Comment

by:CRB1609
ID: 41773403
Thank you Crystal.  Worked wel.l
0
 

Author Comment

by:CRB1609
ID: 41773406
I don't seem to be able to award points and close this question.
0
 
LVL 19
ID: 41779953
you're welcome ~ happy to help
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Suggested Solutions

Title # Comments Views Activity
Reading the code behind a form - via VBA 3 31
Send Meeting Request from Shared Mailbox 3 58
Sum in Split Form 17 27
Access - Rounding an average in a report 3 15
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

856 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