I have found many threads about this topic on many other forums, and a few here on tek-tips. I have tried a bunch of snippets of code from various sources but I cannot get any of them to execute.
I run a report called "rpt_qrySPU03"
It is grouped on a field called UserOrgInd
I want to print the report to individual PDFs where each PDF contains just the data for UserOrgInd and where the name of the PDF is each UserOrgInd and .pdf.
I have the small bit of code to run the reports and convert to PDF, but every technique I have tried to loop through a list of the UserOrgInd field has failed. I'm not even close.
I created a table called tblOrgs which has a field called UserOrg. This UserOrg field contains a unique list of the UserOrgInd so I can use it as a SELECT criteria and as the parameter for naming the PDF.
Here is the code that I use to run the report. Can you help me add the bits I need to
a. reference my table of UserOrgInd
b. start the loop
c. create each grouped PDF per UserOrgInd and named per the UserOrgInd parameter
d. stop the loop
Also an example of something that is totally not working and I've stepped on this so many times it's baby food. I know there a ton of stuff missing and it's embarrassing even posting this:
I run a report called "rpt_qrySPU03"
It is grouped on a field called UserOrgInd
I want to print the report to individual PDFs where each PDF contains just the data for UserOrgInd and where the name of the PDF is each UserOrgInd and .pdf.
I have the small bit of code to run the reports and convert to PDF, but every technique I have tried to loop through a list of the UserOrgInd field has failed. I'm not even close.
I created a table called tblOrgs which has a field called UserOrg. This UserOrg field contains a unique list of the UserOrgInd so I can use it as a SELECT criteria and as the parameter for naming the PDF.
Here is the code that I use to run the report. Can you help me add the bits I need to
a. reference my table of UserOrgInd
b. start the loop
c. create each grouped PDF per UserOrgInd and named per the UserOrgInd parameter
d. stop the loop
Code:
Private Sub Command1_Click()
Dim MyPath As String
Dim MyFilename As String
Dim rs As DAO.Recordset
MyPath = "W:\report"
MyFilename = "blah" & ".pdf"
DoCmd.OpenReport "rpt_qrySPU03", acViewPreview, "qrySPU03"
DoCmd.OutputTo acOutputReport, "", acFormatPDF, MyPath & "\" & MyFilename, False
End Sub
Also an example of something that is totally not working and I've stepped on this so many times it's baby food. I know there a ton of stuff missing and it's embarrassing even posting this:
Code:
Private Sub Command3_Click()
'Load recordset
Dim strSQL As String
strSQL = "SELECT * FROM tblOrgs"
Set db = CurrentDb
Set rs = OpenRecordset(tblOrgs)
Dim strReportName As String
strReportName = "rpt_qrySPU03"
'Loop over records
Do Until rs.EOF
'To open a report
DoCmd.OpenReport strReportName, acViewNormal, , "UserOrg=" & rsComp!UserOrg, acHidden
DoCmd.OutputTo acOutputReport, "", acFormatPDF, MyPath & UserOrg, False
rsComp.MoveNext
Loop
'Cleanup
Set rsComp = Nothing
End Sub