when it runs, it creates all the directories and access crashes. in the directory there is a .tmp file (pdf temp file). restart access since directories are now there, it will create the PDF files as planned. Thanks
Code:
Private Sub CreatePDF_Click()DoCmd.RunCommand acCmdSaveRecord
Dim UserVenuePath As String
Dim strFilePath As String
Dim strFileName As String
Dim strReport As String
Dim Venue As String
UserVenuePath = DLookup("[FilePath]", "tbl_SystemInfo", "[SystemInfoID] = 1")
Venue = DLookup("[Venue]", "tbl_SystemInfo", "[SystemInfoID] = 1")
strFilePath = UserVenuePath & Environ("username") & "\OneDrive - Caterers In The Park\" & Venue & "\Contracts\" & Format(Forms!frm_Contract.DateofFunction, "MM-DD-yyyy") & "\" & Forms!frm_Contract.DayTimeFunction & "\"
strFileName = Forms!frm_Contract.NameonContract & ".pdf"
MakePDF = MsgBox(strFilePath, vbOKCancel, "Create PDF for " & strFileName)
If MakePDF = vbOK Then
If FolderExists(strFilePath) = False Then
Call MakeDir(strFilePath)
Else
MsgBox "This folder already exists.", vbInformation, "Folder Exists"
End If
'First let's open the report
strReport = "rpt_Contract"
'DoCmd.OpenReport strReport, acViewPreview, , "[ContractsID] = [Forms]![frm_Contract]![ContractsID]", acWindowNormal
'Now let's save the open report to .PDF
DoCmd.OutputTo acOutputReport, strReport, acFormatPDF, strFilePath & strFileName, False
'DoCmd.Close acReport, strReport
'Display Message
MsgBox "New file has created successfully in the new folder!", vbInformation, "VBAF1"
End If
End Sub