The OutputTo action was cancelled

setis

Registered User.
Local time
Yesterday, 20:48
Joined
Sep 30, 2017
Messages
127
Dear all, I am getting this error on the below VB for a button that should create a folder and place a PDF of a report in it.

The code is working on another report created previously and I just updated the FilePath and FileName.

It creates the folder correctly, but I get the OutputTo error. If I try a second time, it says that the folder already exists. I don't believe that it should happen either..

Could somebody figure out what I am missing?



Code:
Private Sub Command247_Click()
' FILESYSTEMOBJECT/SCRIPTING
Dim FSO As Scripting.FileSystemObject
Set FSO = New Scripting.FileSystemObject

Dim FileName As String
Dim FilePath As String
Dim FolderName As String
Dim FP As String


FolderName = Me.cmbCasNo
FileName = Me.cmbCasNo & "-InvNr" & Me.InvoiceNr & ".pdf"
FP = "G:\XXXX"

If Not FSO.FolderExists(FP & "" & FolderName) Then
    FSO.CreateFolder (FP & "\" & FolderName)
End If
FilePath = "G:\XXXX" & FolderName & "\" & FileName

If Len(Dir(FilePath)) > 0 Then
    If MsgBox("This Audit has already been saved." & vbCrLf & "Do you want to overwrite it with an updated copy?", vbYesNo, "Overwrite Existing File?") = vbYes Then
        Kill FilePath
    Else
        Exit Sub
    End If
End If

DoCmd.OutputTo acOutputReport, "repClaims", acFormatPDF, FilePath

MsgBox "The Audit Sheet has been saved", vcinformation, "Save Confirmed"

End Sub
 
to skip the errors, put in :

On Error resume next
FSO.CreateFolder (FP & "" & FolderName)

so if the folder already exists, it will ignore the error and move on.
Also, FP should have the backslash: FP = "G:\XXXX\"
because you forgot it here:
FilePath = "G:\XXXX" & FolderName & "" & FileName

so:
FilePath = FP & FolderName & "" & FileName

PS.
I see this site wont allow single slashes.
 
Also, FP should have the backslash: FP = "G:\XXXX"
because you forgot it here:
FilePath = "G:\XXXX" & FolderName & "" & FileName

Thank you! It was the backslash!
 

Users who are viewing this thread

Back
Top Bottom