Export report to PDF with filename and filepath (1 Viewer)

Jonny45wakey

Member
Local time
Today, 21:17
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
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:17
Joined
May 7, 2009
Messages
19,246
can you do "extra" step.
save it locally and then FileCopy it to the network location.
 

Gasman

Enthusiastic Amateur
Local time
Today, 21:17
Joined
Sep 21, 2011
Messages
14,472
Missing the : for the drive letter?
 
Last edited:

alcalde

New member
Local time
Today, 22:17
Joined
Oct 31, 2022
Messages
9
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"
 

Gasman

Enthusiastic Amateur
Local time
Today, 21:17
Joined
Sep 21, 2011
Messages
14,472
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.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:17
Joined
Feb 19, 2002
Messages
43,513
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

Top Bottom