Solved Saving Report As PDF on desktop

theinviter

Registered User.
Local time
Today, 03:55
Joined
Aug 14, 2014
Messages
273
HI
i wanna save a report as PDF file.
but always get Error; invalid folder path,
i tried

Dim fileName As String, fldrPath As String, filePath As String
Dim answer As Integer

fileName = "Member Contact Details" 'filename for PDF file*

fldrPath = "C:\Users\Default\Desktop" 'folder path where pdf file will be saved *

filePath = fldrPath & "\" & fileName & ".pdf"

'check if file already exists
If FileExist(filePath) Then
answer = MsgBox(prompt:="PDF file already exists: " & vbNewLine & filePath & vbNewLine & vbNewLine & _
"Would you like to replace existing file?", buttons:=vbYesNo, Title:="Existing PDF File")
If answer = vbNo Then Exit Sub
End If

On Error GoTo invalidFolderPath
DoCmd.OutputTo objecttype:=acOutputReport, objectName:=Me.Name, outputformat:=acFormatPDF, outputFile:=filePath

MsgBox prompt:="PDF File exported to: " & vbNewLine & filePath, buttons:=vbInformation, Title:="Report Exported as PDF"
Exit Sub

invalidFolderPath:
MsgBox prompt:="Error: Invalid folder path. Please update code.", buttons:=vbCritical
End Sub



Function FileExist(FileFullPath As String) As Boolean


Dim value As Boolean
value = False
If Dir(FileFullPath) <> "" Then
value = True
End If
FileExist = value
End Function
 
In future, please post code between CODE tags.

This example worked for me:
Code:
DoCmd.OutputTo acOutputReport, "Compensation", acFormatPDF, Environ("USERPROFILE") & "\Desktop\Comp.pdf"
I tried and failed:
"C:\Users\Default\Desktop\Comp.pdf"
and
"C:\Users\Public\Desktop\Comp.pdf"
 
Last edited:
Pat, the "\" is concatenated in the next line that appends the file name.
 
Not disagreeing with principle. Just saying that was not code error. I have encountered issue with programmatically saving files into user folder. Seems IT put a block on that. Had to rewrite some code.
 
No. I am not working with a network. Will let OP test if they want.
 

Users who are viewing this thread

Back
Top Bottom