I may be way off base here with regard to my code, but this is my attempt. Veteran coders...no laughs please, I'm new to Access.
I am trying to create a pdf from an Access report. Here is the code on my main form reports tab:
private sub:
and here is the function:
The error I'm getting is 2059 "cannot find the object 'stDocName'
Any help is appreciated.
I am trying to create a pdf from an Access report. Here is the code on my main form reports tab:
private sub:
Code:
Dim stDocName As String
stDocName = Me.lstReportName.Column(1) 'the name of the report
DoCmd.OpenReport stDocName, acPreview
If Me.chkSaveAsPdf.Value = -1 Then
Call SaveAsPdf(stDocName)
End If
Code:
Public Function SaveAsPdf(stDocName As String)
Dim rptDate As String
Dim strAppPath As String
Dim rptPath As String
Dim MyFilename As String
rptDate = Now()
'MsgBox rptDate
'store the full path to our current project
strAppPath = CurrentProject.Path & "\"
'store the file in a different folder depending on the date
rptPath = "strAppPath" & Format(rptDate, "yyyy")
'store the filename as MM-DD-YYYY-[reportname].pdf
MyFilename = Format(rptDate, "mm") & _
"-" & Format(rptDate, "dd") & Format(rptDate, "yyyy") & _
"-" & "stDocName" & ".pdf"
'save the file. Once you see it works, you can change True to False so that the file created
'is not opened after completion.
DoCmd.OutputTo acOutputReport, "stDocName", acFormatPDF, "rptPath" & MyFilename, True, , , acExportQualityPrint
End Function
Any help is appreciated.
Comment