A
Antney
Hi,
I have code that turns my Access reports into PDFs but for some reason when
the filter in the code gets done with one school, it should start at the next
school in the list but the code starts all over again at the first school. So
the code goes through the table but always starts at the first school instead
of cycling through all of them until the end of file. Can anyone help me
figure this out? I want the code to go through all of the schools in the
table.
Thanks!!!
Here is my code:
Option Compare Database
Option Explicit
Private Sub cmdConvertReportsToPDF_Click()
On Error GoTo Err_cmdConvertReportsToPDF_Click
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strReport As String
Dim strDocName As String
Dim blRet As Boolean
Dim strDocFolder As String
Dim strFilter As String
Set db = CurrentDb()
'Recordsource
Set rs = db.OpenRecordset("SnapshotData_Elem")
'Report
strReport = "rptStudentSnapshot_Elem"
'Path to output PDFs
strDocFolder = "Z:\RAADataSupport\Student Snapshots\Student Snapshot
Elementary\"
Do Until rs.EOF
'Labels the PDF file with the school name
strDocName = strDocFolder & "Student Snapshot Fall 2008 " &
rs!SiteName & ".pdf"
'Recordsource school id matches report school id
strFilter = "School=" & rs!School
DoCmd.OpenReport strReport, acViewPreview, , strFilter,
acHidden
If Reports(strReport).HasData Then
'Calls the ConvertReportToPDF function
blRet = ConvertReportToPDF(strReport, vbNullString,
strDocName, False, False, 150, "", "", 0, 0, 0)
rs.MoveNext
End If
DoCmd.Close acReport, strReport
Loop
rs.Close
Exit_cmdConvertReportsToPDF_Click:
'Cleanup
On Error Resume Next
rs.Close: Set rs = Nothing
db.Close: Set db = Nothing
Exit Sub
Err_cmdConvertReportsToPDF_Click:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in Test subroutine..."
Resume Exit_cmdConvertReportsToPDF_Click
End Sub
I have code that turns my Access reports into PDFs but for some reason when
the filter in the code gets done with one school, it should start at the next
school in the list but the code starts all over again at the first school. So
the code goes through the table but always starts at the first school instead
of cycling through all of them until the end of file. Can anyone help me
figure this out? I want the code to go through all of the schools in the
table.
Thanks!!!
Here is my code:
Option Compare Database
Option Explicit
Private Sub cmdConvertReportsToPDF_Click()
On Error GoTo Err_cmdConvertReportsToPDF_Click
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strReport As String
Dim strDocName As String
Dim blRet As Boolean
Dim strDocFolder As String
Dim strFilter As String
Set db = CurrentDb()
'Recordsource
Set rs = db.OpenRecordset("SnapshotData_Elem")
'Report
strReport = "rptStudentSnapshot_Elem"
'Path to output PDFs
strDocFolder = "Z:\RAADataSupport\Student Snapshots\Student Snapshot
Elementary\"
Do Until rs.EOF
'Labels the PDF file with the school name
strDocName = strDocFolder & "Student Snapshot Fall 2008 " &
rs!SiteName & ".pdf"
'Recordsource school id matches report school id
strFilter = "School=" & rs!School
DoCmd.OpenReport strReport, acViewPreview, , strFilter,
acHidden
If Reports(strReport).HasData Then
'Calls the ConvertReportToPDF function
blRet = ConvertReportToPDF(strReport, vbNullString,
strDocName, False, False, 150, "", "", 0, 0, 0)
rs.MoveNext
End If
DoCmd.Close acReport, strReport
Loop
rs.Close
Exit_cmdConvertReportsToPDF_Click:
'Cleanup
On Error Resume Next
rs.Close: Set rs = Nothing
db.Close: Set db = Nothing
Exit Sub
Err_cmdConvertReportsToPDF_Click:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in Test subroutine..."
Resume Exit_cmdConvertReportsToPDF_Click
End Sub