Solved

Button Code to Save Access 2013 Report to PDF has stopped working?

Posted on 2015-01-05
8
281 Views
Last Modified: 2015-01-10
Hi all, I created a simple Access 2013 project that has a single table, a form and a report.  The form has entry for all fields on the table and then a button at the bottom of the form.  The button has code behind it which is supposed to print the current record details using the report and then save the current report as a PDF to 2 different locations.  As I am a novice with Access, I had help to get this working but did get it all working and has been working fine for about 6 months now.  I just noticed today that the saved PDF's of the reports have no data on them?  It saves the report to a PDF in the correct location but when you open the PDF, you just see the report as it was designed but the actual data fields have no data in them?  When looking back at the data, it has been doing this now for about a month.  I will attach the code I use to accomplish this and display below.  Thank you for your help!  I am using Access 2013 32-bit as part of 365 and running on Windows 7 64-bit with SP1.

Private Sub PrintCurrent_Click()
'Print current record
'using JobTicket report
'then Save to Desktop as PDF
Dim strReport As String
Dim strFileName As String
Me.Dirty = False
If IsNull(Me!ID) Then
MsgBox "Please select a valid record", _
vbOKOnly, "Error"
Exit Sub
End If
DoCmd.OpenReport "JobTicket", acViewNormal, , "ID =" & Me.ID
strReport = "JobTicket"
strFileName = "C:\Users\Zund\Desktop\" & Year([Entry Date]) & "-" & Me.[Jobnum] & ".pdf"
DoCmd.OutputTo acOutputReport, strReport, acFormatPDF, strFileName
strReport = "JobTicket"
strFileName = "W:\MASTER JOB TICKETS\" & Year([Entry Date]) & "-" & Me.[Jobnum] & ".pdf"
DoCmd.OutputTo acOutputReport, strReport, acFormatPDF, strFileName
End Sub

Private-Sub-PrintCurrent.docx
0
Comment
Question by:mjchevalier
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 34

Expert Comment

by:PatHartman
ID: 40531940
Sounds like a new bug introduced in the past month.  I would report it to Microsoft.

In the mean time, you can modify your method.  I am using A2013 and don't have a problem exporting to pdf.  I use a different method though.  The OutputTo method does not support a where argument the way the OpenReport method does so rather than open the report in print preview first and then outputting the open report, I have the report's RecordSource query get its argument directly from the form.

Select ...
From ...
Where ID = Forms!yourform!ID;

Using that technique, you should get rid of the OpenReport.
0
 

Author Comment

by:mjchevalier
ID: 40532096
Thanks PatHartman.  I went back to the report and looked at the RecordSource and found that it is currently set to:

SELECT * FROM JobTicket WHERE (((JobTicket.[ID])=[Forms]![JobNum]![ID]));

So now I am confused because apparently I am already doing what you have asked me to do?  I am not sure where to go from here now???
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 40532275
Try these three things:
1. Compile your code, ...retest
2. Create a blank database and import all of the objects, ...retest
Try the code as something similar to this syntax:
    'Set the name of the Report
    strReport="YourReport"
    'Open the report in Print Preview mode, filtered for the current ID, and Hidden
    DoCmd.OpenReport strReport, acViewPreview, , "ID=" & Me.ID, acHidden
    'Set the output file specs
    strFileName = "C:\YourFolder\" & Year([OrderDate]) & "-" & Me.[CustID] & ".pdf"
    'Output this Report to a PDF
    DoCmd.OutputTo acOutputReport, strReport, acFormatPDF, strFileName
    DoCmd.Close acReport, strReport

...Then retest...

Also, ...can you export the report as a PDF from the menus? (or right-tclicking the report from the navigation pane?)

JeffCoachman
0
 

Accepted Solution

by:
mjchevalier earned 0 total points
ID: 40532317
I fixed it myself by adding a ", False" to the end of each OutputTo command and that did it.  Thanks for the help but this one I fixed.
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 34

Expert Comment

by:PatHartman
ID: 40532860
because apparently I am already doing what you have asked me to do
No.  You were still opening the report in print preview first (and I said not to) and so the OutputTo was using the open version of the report rather than opening its own.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 40532871
...odd because:
AutoStart:false
...is presumed if this argument is left out...
0
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 40534068
There is no need to open the report first -- just the OutputTo line works fine (supposing the various arguments have been set correctly).  I would replace the reference to a value on a form with a saved value, either in a global variable or a custom database property, so the value won't disappear if the form is closed.
0
 

Author Closing Comment

by:mjchevalier
ID: 40541769
I was able to find the solution myself through testing and adding a statement to the code.
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

Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

910 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

20 Experts available now in Live!

Get 1:1 Help Now