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

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

Posted on 2015-01-05
8
290 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 36

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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

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
 
LVL 36

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

828 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