Export report to PDF with filename and filepath

Jonny45wakey

Member
Local time
Today, 12:14
Joined
May 4, 2020
Messages
40
Hi hoping someone can point out the errors in my VBA code please

I'm trying to export a report to PDF with a filename and filepath on a CMD button on click event

My current code is as follows but i keep getting a VBA Runtime error 2501 OutputTo action cancelled

Private Sub Cmd133_Click()
Dim Filename As String
Dim Filepath As String
Dim Reportname As String

Reportname = "rptInvoice"
Filename = Me.Customer & Me.InvoiceNo
Filepath = "S\Invoicing\" & Filename & ".pdf"
DoCmd.OutputTo acOutputReport, "rptInvoice", acFormatPDF, Filename & Filepath

MsgBox "Invoice has been exported to Network Location Commonshare\Invoicing", vbInformation, "Export Confirmed"

End Sub
 
can you do "extra" step.
save it locally and then FileCopy it to the network location.
 
Missing the : for the drive letter?
 
Last edited:
It is not allowed to use the Backslash [/] and the colon [:] in the file name
try to replace them with the underscore [_]
Filepath = "S_Invoicing_" & Filename & ".pdf"
 
It is not allowed to use the Backslash [/] and the colon [:] in the file name
try to replace them with the underscore [_]
Filepath = "S_Invoicing_" & Filename & ".pdf"
That is a forward slash?, plus the : is for the drive.
 
You seem to have typos in your hard-coded string.

Put a stop on the DoCmd. line and print the filename and filepath to the immediate window and post that if you can't see the typo.
 

Users who are viewing this thread

Back
Top Bottom