423,319 Members | 2,562 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,319 IT Pros & Developers. It's quick & easy.

When I save a pdf from Access, it only shows a blank report

P: 1
Hello everyone,

I have created a simple, so I thought, database to track and provide receipts of applications received. I have written a VB script that does everything I need to do, but it saves a blank report. Am I missing something?

Here is the script:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command21_Click()
  2. Dim myPath As String
  3. Dim strReportName As String
  4. DoCmd.OpenReport "Rpt - Receipt", acViewPreview, "Me.Number =" & Me.Last_Name, acWindowNormal
  5.  
  6. myPath = "S:\acc database\Application Receipt Database\App Receipts pdf\"
  7. strReportName = [Number] & "-" & [Last Name] & ".pdf"
  8. DoCmd.OutputTo acOutputReport, "Rpt - Receipt", acFormatPDF, myPath + strReportName, True
  9.  
  10. MsgBox "Receipt saved as PDF", vbInformation, "Save Confirmed"
  11.  
  12. DoCmd.Close acReport, "Rpt - Receipt"
Jul 10 '18 #1
Share this Question
Share on Google+
2 Replies


twinnyfo
Expert Mod 2.5K+
P: 2,535
rguim03,

Welcome to Bytes!

At first glance, what is happening is that you are opening the Report twice--which is unnecessary (Line 4 and Line 8). You are also calling a filter on your report in line 4 (which is not getting saved to PDF), and then saving the report as a PDF without that filter.

We've seen this before, and the way to do this is to declare a public variable that you establish as the Rerport's filter. Then, as you cycle through your records, you set the Filter String and save the report. The Report will have a brief bit of code in the OnOpen event that will filter the Report based upon that filter string.

I can provide greater detail if needed, but this is the general direction you need to go.
Jul 10 '18 #2

zmbd
Expert Mod 5K+
P: 5,279
rguim03:
Guessing here:
In your database you have a report named "Rpt - Receipt"

If you open that report directly, it opens blank - yes?

Line #8 (DoCmd.OutputTo) takes the existing report, based on its original dataset, not the open report, and saves it out. VBA Refernce DoCmd.OutputTo

Without much detail it's hard to suggest a course of action to obtain the desired results; however, I have a report that I use for both a single entry report as-well-as group reports based on a query that uses references to a couple of the [TempVars] collection values for the conditions and then saves the report out.

(partial SQL, the whole thing is huge...)
Expand|Select|Wrap|Line Numbers
  1. SELECT t_testkit.pk_testkit
  2. FROM t_testYear 
  3.   INNER JOIN t_testkit 
  4.     ON t_testYear.PK_testYear = t_testkit.fk_testYear
  5. WHERE (((t_testkit.fk_testYear) 
  6.     Like [TempVars]![ReportYears]))
  7. ORDER BY t_testkit.fk_testYear;
So, I set the [Tempvars]![ReportYears] value to the year in question and then issue the DoCmd.OutputTo which then saves the report, based on the afore mentioned query which runs using the value stored in the [Tempvars]![ReportYears] before saving the report...

There are ofcourse a dozen other methods; howevr, the [TempVars] collection has made this so much easier to accomplish.
Jul 10 '18 #3

Post your reply

Sign in to post your reply or Sign up for a free account.