E
Evon
I have a button on a form that should allow me to open a report,
filter it to a single supervisor's information, output it to a pdf
file and then it SHOULD move to the next record and do it all over
again. What it's really doing, however, is opening the report for a
single supervisor and then outputting that same report 35 times (there
are 35 supervisors, hence 35 iterations in the loop). Can someone
help me understand why the rs.MoveNext isn't working? Many thanks for
any help!
Option Compare Database
_____________________________________________________________________________________________
Private Sub Command8_Click()
Dim strReport As String
Dim strWhere As String
Dim strSave As String
Dim strPath As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("qry_Convert_Supervisor")
strReport = "Recall Roster"
strWhere = "Supv ='" & Sup_ID & "'"
strPath = Left(CurrentDb.Name, InStrRev(CurrentDb.Name, "\", ,
vbTextCompare))
strPDF = strPath & "Reports\" & strPDF
strPDF = Replace(strPDF, "\", "\\")
strSave = strPDF & Me.Sup_LName & "_" & Format(Date, "yymmdd") &
".pdf"
'create the directory to save reports to if it doesn't exist
If Dir(strPath & "Reports\", vbDirectory) = "" Then
MkDir strPath & "Reports\"
End If
'move to the beginning of the recordset
rs.MoveFirst
'begin loop
Do Until rs.EOF
'create temporary registry entry to allow saving pdf files
SaveSetting "Dane Prairie Systems", "Win2PDF", "PDFFileName",
strSave
'set the printer to the Win2PDF application **THIS MUST BE SET AS THE
DEFAULT PRINTER**
Application.Printer = Application.Printers("Win2PDF")
'open / print the report
DoCmd.OpenReport strReport, acViewNormal, , strWhere
'close the report
DoCmd.Close acReport, strReport
'move to the next record
rs.MoveNext
'if the loop is complete then exit
If rs.EOF Then Exit Do
'repeat the loop if not end of file
Loop
'close the recordset
rs.Close
Exit Sub
End Sub
filter it to a single supervisor's information, output it to a pdf
file and then it SHOULD move to the next record and do it all over
again. What it's really doing, however, is opening the report for a
single supervisor and then outputting that same report 35 times (there
are 35 supervisors, hence 35 iterations in the loop). Can someone
help me understand why the rs.MoveNext isn't working? Many thanks for
any help!
Option Compare Database
_____________________________________________________________________________________________
Private Sub Command8_Click()
Dim strReport As String
Dim strWhere As String
Dim strSave As String
Dim strPath As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("qry_Convert_Supervisor")
strReport = "Recall Roster"
strWhere = "Supv ='" & Sup_ID & "'"
strPath = Left(CurrentDb.Name, InStrRev(CurrentDb.Name, "\", ,
vbTextCompare))
strPDF = strPath & "Reports\" & strPDF
strPDF = Replace(strPDF, "\", "\\")
strSave = strPDF & Me.Sup_LName & "_" & Format(Date, "yymmdd") &
".pdf"
'create the directory to save reports to if it doesn't exist
If Dir(strPath & "Reports\", vbDirectory) = "" Then
MkDir strPath & "Reports\"
End If
'move to the beginning of the recordset
rs.MoveFirst
'begin loop
Do Until rs.EOF
'create temporary registry entry to allow saving pdf files
SaveSetting "Dane Prairie Systems", "Win2PDF", "PDFFileName",
strSave
'set the printer to the Win2PDF application **THIS MUST BE SET AS THE
DEFAULT PRINTER**
Application.Printer = Application.Printers("Win2PDF")
'open / print the report
DoCmd.OpenReport strReport, acViewNormal, , strWhere
'close the report
DoCmd.Close acReport, strReport
'move to the next record
rs.MoveNext
'if the loop is complete then exit
If rs.EOF Then Exit Do
'repeat the loop if not end of file
Loop
'close the recordset
rs.Close
Exit Sub
End Sub