Save a report to a PDF file.

Zorik2

New member
Local time
Today, 15:59
Joined
Feb 21, 2013
Messages
3
Hi I have this piece of code to save a one-page report (a receipt) to a PDF file.
for some unknown reason it usually works, but I find it unstable at times , and fails to execute the "DoCmd.OutputTo" command.
Trying to work it out, I found that if fails because of the strFName variable.

Dim strPath, strFName, strRptName As String

strPath = DLookup("[KabalotPath]", "tblMainPrmtrs") & "\"
strFName = strPath
strFName = strFName & "Rec " & txtNumKabala
strFName = strFName & " " & "Apt " & txtDiraID & " " & txtDayar & ".pdf"

If Dir(strFName) = "" Then
strRptName = Me.Name
DoCmd.OutputTo acOutputReport, strRptName, acFormatPDF, strFName
End if

Thx for your help
Shlomo
 
If you have spaces in the file name, you may need surround the full path filename and extension with quotes.

Also, you should add string to the other variables.

Dim strPath as String, strFName as String, strRptName As String
 
Hi Shlomo. Welcome to AWF!

Another potential source of problem is if you have "illegal characters" in the strFName variable. Some characters are not allowed to be used in a file name.
 
I have found DoCmd.OutputTo to be unstable unless you Open the item in question, first. You might try a line of code that opens the report and then runs DoCmd.OutputTo, and then closes it , see if that causes any improvement? I blogged about that here
 

Users who are viewing this thread

Back
Top Bottom