I am guessing you are looking up "UserVenuePath" in a table (tbl_SystemInfo) in the current dB (which is supposed to evaluate to a user's name?).
The path points to One Drive; somehow you get the Caterer Name (is there more than one Caterer?).
Looking at the posted code:
Code:
Private Sub Command276_Click() Terrible name for a button (I am guessing it is a button).
You are referencing 3 controls on form "frm_Contract" using syntax like
Code:
Form_frm_Contract.DateofFunction
"Form_frm_Contract" is how Access keeps track of form/report object names. It is not a good idea, but you can/could have a FORM named "Test1" AND a REPORT named "Test1"
In the IDE, the prefix "Form_" and "Report_" is how Access allows for both objects to have the same name.
You should be using Me.DateofFunction or [Forms]![frm_Contract]![controlname] (<<-- change controlname to the actual control names)
In the OpenReport command, you need to concatenate the value to the field name.
if ContractsID is numeric, use
Code:
DoCmd.OpenReport strReport, acViewPreview, , "[ContractsID] = " & [Forms]![frm_Contract]![ContractsID], acWindowNormal
if ContractsID is text, then use
Code:
DoCmd.OpenReport strReport, acViewPreview, , "[ContractsID] = '" & [Forms]![frm_Contract]![ContractsID] & "'", acWindowNormal
To export the report to PDF, you don't need to open the report first.
From help:
ObjectName (Optional Variant)
A string expression that's the valid name of an object of the type selected by the ObjectType argument. If you want to output the active object, specify the object's type for the ObjectType argument and
leave this argument blank.
Because you have "strReport" as the ObjectName parameter, the command is not using the selected object - it is using the saved report. Hopefully the report record source has a WHERE clause.
Consider this code (rename the sub - maybe "btnExportRptToPDF):
Code:
Private Sub Command276_Click()
Dim UserVenuePath As String
Dim strFilePath As String
Dim strReport As String
' DoCmd.RunCommand acCmdSaveRecord
Me.Dirty = False
UserVenuePath = DLookup("[FilePath]", "tbl_SystemInfo", "[SystemInfoID] = 1")
strFilePath = UserVenuePath & "\Contracts\" & Format(Forms!frm_Contract.DateofFunction, "MM-DD-yyyy") & "\" & Forms!frm_Contract.DayTimeFunction & "\"
strFileName = Forms!frm_Contract.NameonContract & ".pdf"
If FolderExists(strFilePath) = False Then
Call MakeDir(strFilePath)
Else
MsgBox "This folder already exists.", vbInformation, "Folder Exists"
End If
strReport = "rpt_Contract"
'Save the report to .PDF
DoCmd.OutputTo acOutputReport, strReport, acFormatPDF, strFilePath & strFileName, False
'Display Message
MsgBox "New file has created successfully in the new folder!", vbInformation, "VBAF1"
End Sub