Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 304
  • Last Modified:

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

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
mjchevalier
Asked:
mjchevalier
  • 3
  • 2
  • 2
  • +1
1 Solution
 
PatHartmanCommented:
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
 
mjchevalierAuthor Commented:
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
 
Jeffrey CoachmanCommented:
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
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!

 
mjchevalierAuthor Commented:
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
 
PatHartmanCommented:
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
 
Jeffrey CoachmanCommented:
...odd because:
AutoStart:false
...is presumed if this argument is left out...
0
 
Helen FeddemaCommented:
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
 
mjchevalierAuthor Commented:
I was able to find the solution myself through testing and adding a statement to the code.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now