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?
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