put filter on load to YES and used
Code:
DoCmd.OutputTo acOutputReport, strReport, acFormatPDF, strFilePath & strFileName, False
much faster and cleaner. Thanks Steve and Vlad
new code looks like this
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 - Caterer\" & 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.SelectObject acReport, strReport
'DoCmd.OutputTo acOutputReport, strReport, acFormatPDF, strFilePath & strFileName, False, , , acExportQualityPrint
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