Hi there,
I've been trying to save down access reports as PDFs programmably from excel vba, the access report is based on a parameter driven Access Query. The code runs fine if I run the .DoCmd.OpenReport without the where condition and the 'Enter Parameter Value' dialogue boxes would just pop up and I'd be able to enter the start and end dates and get the reports saved for the date range. However, if I have the where condition it would save a report with no what appears to be no data selected since the values are all zero.
(code)
Sub ReportSave(ByRef strReport As String)
Dim objAccess As Object
Dim objDB As Object
Dim strDest As String
Dim strDB As String
Dim strMonth As String
Dim startDate As String
Dim endDate As String
startDate = Format(Sheets("Settings").Range("B6").Value, "dd/mm/yyyy")
endDate = Format(Sheets("Settings").Range("B7").Value, "dd/mm/yyyy")
strDB = Sheets("Settings").Range("B2").Value
strDest = Sheets("Settings").Range("B3").Value
strMonth = Sheets("Settings").Range("B5").Value
Set objAccess = CreateObject("Access.Application")
objAccess.OpenCurrentDatabase strDB, False
'Use objAccess for the DoCmd
objAccess.DoCmd.OpenReport strReport, acViewReport, , "[Start Date]=#" & startDate & "# And [first day in new period]=#" & endDate & "#"
objAccess.DoCmd.OutputTo acOutputReport, , acFormatPDF, strDest & strReport & "_" & strMonth & ".pdf"
objAccess.Quit
Set objAccess = Nothing
End Sub
(code)
I've been trying to save down access reports as PDFs programmably from excel vba, the access report is based on a parameter driven Access Query. The code runs fine if I run the .DoCmd.OpenReport without the where condition and the 'Enter Parameter Value' dialogue boxes would just pop up and I'd be able to enter the start and end dates and get the reports saved for the date range. However, if I have the where condition it would save a report with no what appears to be no data selected since the values are all zero.
(code)
Sub ReportSave(ByRef strReport As String)
Dim objAccess As Object
Dim objDB As Object
Dim strDest As String
Dim strDB As String
Dim strMonth As String
Dim startDate As String
Dim endDate As String
startDate = Format(Sheets("Settings").Range("B6").Value, "dd/mm/yyyy")
endDate = Format(Sheets("Settings").Range("B7").Value, "dd/mm/yyyy")
strDB = Sheets("Settings").Range("B2").Value
strDest = Sheets("Settings").Range("B3").Value
strMonth = Sheets("Settings").Range("B5").Value
Set objAccess = CreateObject("Access.Application")
objAccess.OpenCurrentDatabase strDB, False
'Use objAccess for the DoCmd
objAccess.DoCmd.OpenReport strReport, acViewReport, , "[Start Date]=#" & startDate & "# And [first day in new period]=#" & endDate & "#"
objAccess.DoCmd.OutputTo acOutputReport, , acFormatPDF, strDest & strReport & "_" & strMonth & ".pdf"
objAccess.Quit
Set objAccess = Nothing
End Sub
(code)