Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New Computer and Save As PDF code no longer saving to specified file name or location 1

Status
Not open for further replies.

sxschech

Technical User
Jul 11, 2002
1,033
US
I've been using the code from for several years successfully. Recently was given a new computer and while the code runs and no errors (no pop up message boxes or halt in the program) instead of having the report saved with the name generated by vba and to the location specified by vba, the reports are outputted with the actual access report name as shown in the database window. Also instead of saving the report to the server, it is saving locally to the hard drive. Fortunately, IT has let me hang on to the old computer during the transition, so I did a side by side comparison of the settings in acrobat and distiller and did not see anything different in the preferences. Other than the computer being new, the differences between the two computers are the new one is using Windows 7 64 bit, while the old computer is running Windows 7 32 bit. Other than that, the software is same, Access 2010 version 14.0.6129.5000 (32-bit); Acrobat 9 Pro version 9.2.0.
 
I am kind of confused on all of that code. If I want to save a report as a PDF to some location I just need one line of code.
Code:
Public Sub SaveReportAsPDF(rptName As String, strFilePathAndName As String)
  DoCmd.OutputTo acOutputReport, rptName, acFormatPDF, strFilePathAndName, False
End Sub

this save the report "rptShippers", to the location and file name I want.
Code:
Public Sub TestOutput()
  SaveReportAsPDF "rptShippers", "C:\Shippers.PDF"
End Sub
 
Thanks for the simplified code. I think I had tried something like that before, but the output didn't look right, which is why I went back to the complicated code. I'm trying out your vba suggestion and some of the text looks funny (stretched out). I opened one of the reports in design view and noticed that the font for the stretched out text had a printer icon, I tried a different font with a TT icon and that seems to look a little better. Looks like I have a lot of typeface report editing to do in order to use the simplified code for report printing to pdf. Once I've modified the reports and run it through the sub you provided along with the other steps needed to be done by my code to generate the finished output, I'll let you know. If all goes well with this code looks like I can get rid of some other code I have the closes the files since the method provided seems to create the file without showing it on screen as well.
 
Thanks again for your help with this. Greatly simplified the code and processing. Just not sure why typefaces were negatively impacted by this pdf creation code versus the other.
 
Seems that this method doesn't allow the optional where clause to work, so after a bit of searching found a solution. Here is the modified code to allow for an optional where clause. According the posts, looks like the report needs to be opened first and then output to pdf.

Code:
Public Sub SaveReportAsPDF(rptName As String, strFilePathAndName As String, Optional prmWhere As String, Optional prmDirectPrint As Integer)
'New Computer and Save As PDF code no longer saving to specified file name or location
'thread705 -1717276 from MajP
'26-AUG-2013
'******************************
'This part added by sxschech to allow for direct printing
'09-Mar-06
'
If prmDirectPrint = vbYes Then
    DoCmd.OpenReport rptName, acViewPreview, , prmWhere 'Run the report with optional Filter
    Exit Sub
End If
'******************************
'[URL unfurl="true"]http://stackoverflow.com/questions/6614341/access-2007-vba-report-filter-doesnt-work-until-report-is-reloaded[/URL]
If IsNull(prmWhere) Then
    DoCmd.OutputTo acOutputReport, rptName, acFormatPDF, strFilePathAndName, False
Else                            'Run the report with optional Filter
    DoCmd.OpenReport rptName, acViewReport, , prmWhere
    DoCmd.OutputTo acOutputReport, , acFormatPDF, strFilePathAndName, False
    DoCmd.Close acReport, rptName, acSaveNo     '[URL unfurl="true"]http://www.access-programmers.co.uk/forums/showthread.php?t=202457[/URL]
End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top