Solved

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

Posted on 2015-01-05
8
279 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This is an explanation of a simple data model to help parse a JSON feed
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

705 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

14 Experts available now in Live!

Get 1:1 Help Now