Save a report to a PDF file. (1 Viewer)


New member
Local time
Tomorrow, 01:16
Feb 21, 2013
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


Registered User.
Local time
Today, 15:16
Mar 2, 2010
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


I’m here to help
Staff member
Local time
Today, 15:16
Oct 29, 2018
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.


Lifelong Learner
Local time
Today, 15:16
Mar 14, 2017
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

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 23:16
Jul 9, 2003
Another potential source of problem is if you have "illegal characters"

If indeed it is illegal characters, then you might be interested in a function I have acquired which can be found on my website. The Function fStripIllegal" will strip out illegal characters. I believe it was designed to strip illegal characters from spreadsheet names when creating a spreadsheet with VBA code.

Have a look at my website here, it was an answer to a different question, but it nicely demonstrates utilising the function to strip out illegal characters. You can find in the Function "fStripIllegal" in code at the bottom of the page:-

Look for:- "Function fStripIllegal"

On the nifty access website page here:-


Users who are viewing this thread

Top Bottom