Hi,
I have the following sub routine which loops through a number of records and outputs and saves a PDF of the report in its respective folder. I am trying to make the process more efficient by it not opening the report each time and rather have it do it in the background. The trouble is when the report doesn't open the report filter doesn't kick in. Is there a better way of doing this?
Thanks
I have the following sub routine which loops through a number of records and outputs and saves a PDF of the report in its respective folder. I am trying to make the process more efficient by it not opening the report each time and rather have it do it in the background. The trouble is when the report doesn't open the report filter doesn't kick in. Is there a better way of doing this?
Thanks
Code:
Private Sub cmdPDFSiteInfoRecord_Click()
Dim Folderpath As String
Dim RS As DAO.Recordset
Dim db As DAO.Database
Dim reportFilter As String
Dim currentFolderPath As String
Set db = CurrentDb
Set RS = db.OpenRecordset("SiteInfoNewQry")
If Not RS.EOF Then
RS.MoveFirst
Do Until RS.EOF
currentFolderPath = RS!Folderpath
If FolderExists(currentFolderPath) Then
reportFilter = "SiteInfoID = " & RS("SiteInfoID") ' Assuming "ID" is the unique identifier field in the query
DoCmd.OpenReport "rptPrintSiteInfoNew", acViewPreview, , reportFilter
DoCmd.OutputTo acOutputReport, "rptPrintSiteInfoNew", acFormatPDF, currentFolderPath & "\rptSiteInfo.pdf", False
DoCmd.Close acReport, "rptPrintSiteInfoNew"
Else
'MsgBox ("Folder path does not exist.")
End If
RS.MoveNext
Loop
End If
RS.Close
Set RS = Nothing
Set db = Nothing
End Sub