Code to print to PDF & cycle until EOF

A

Antney

Hi, I work for a school district and I have reports, for each school, that I
want to print to PDF. The thing is is that I want the print command button to
print the reports, in PDF format, separating each school in its' own PDF,
create a file name for that school and then send the PDF to a designated
folder. I would like the program to cycle through each school until the end.
If I haven't explained it thoroughly enough or clearly enough, please let me
know.

Can anyone help me out with this? It would be greatly appreciated!
 
A

Antney

Hi and thank you, it was helpful. I have another question;

I've figured out how to print Access reports to PDF but now that I've
printed them, I want, in VBA code, to figure out how I can get the VBA code
to automatically print each reports name, instead of me having to type it in
once the 'File Name' dialog box pops up and then send it automatically to a
specifed folder instead of me again, having to specify a path.

BTW, in my 'qrySchools', which links the school id with the
'rptStudentDataSheet_0708' school id, I do have the school name. That's the
file name I want to use for each respective report.

Here is my code:

Option Compare Database
Option Explicit

Private Sub cmdPrintReports_Click()
On Error GoTo Err_cmdPrintReports_Click

Dim db As DAO.Database
Dim rs As DAO.Recordset

Set db = CurrentDb()
Set rs = db.OpenRecordset("qrySchools", dbOpenSnapshot)

With rs
Do Until (.EOF Or .BOF) = True
DoCmd.OpenReport "rptStudentDataSheet_0708",
View:=acViewNormal, _
WhereCondition:="School = " & rs("School")
rs.MoveNext
Loop
End With

Exit_cmdPrintReports_Click:
'Cleanup
On Error Resume Next
rs.Close: Set rs = Nothing
db.Close: Set db = Nothing
Exit Sub

Err_cmdPrintReports_Click:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in Test subroutine..."
Resume Exit_cmdPrintReports_Click
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top