Loop Printing

A

ap19

I have the following code and I am trying to loop so that all records get
printed. Currently this only prints the first record and stops. Any
suggestions how I can loop through this sequence to print all records...THANKS

Dim stDocName As String

stDocName = "rptL2005_02"
DoCmd.OpenReport stDocName, acPreview
DoCmd.SelectObject acReport, "rptL2005_02", True
DoCmd.PrintOut acPages, 1, 2

stDocName = "rptT2005_05"
DoCmd.OpenReport stDocName, acPreview
DoCmd.SelectObject acReport, "rptt2005_05", True
DoCmd.PrintOut acPages, 1, 1
 
M

Marshall Barton

ap19 said:
I have the following code and I am trying to loop so that all records get
printed. Currently this only prints the first record and stops. Any
suggestions how I can loop through this sequence to print all records...THANKS

Dim stDocName As String

stDocName = "rptL2005_02"
DoCmd.OpenReport stDocName, acPreview
DoCmd.SelectObject acReport, "rptL2005_02", True
DoCmd.PrintOut acPages, 1, 2

stDocName = "rptT2005_05"
DoCmd.OpenReport stDocName, acPreview
DoCmd.SelectObject acReport, "rptt2005_05", True
DoCmd.PrintOut acPages, 1, 1


You can not do that and have multiple copies of the same
report open at the same time. If a report is already open
the best you can hope for is that the focus moves to the
already displayed report. In some cases, the report can end
up being a mish mash of both sets of data.

If you were printing instead of previewing, then add code to
wait for the report to close before going around the loop.

Why are you using Printout to print selected pages? It
would normally be better to filter the report or make the
unanted sections invisible so it only produces the pages you
want printed.
 
J

John W. Vinson

I have the following code and I am trying to loop so that all records get
printed. Currently this only prints the first record and stops. Any
suggestions how I can loop through this sequence to print all records...THANKS

Dim stDocName As String

stDocName = "rptL2005_02"
DoCmd.OpenReport stDocName, acPreview
DoCmd.SelectObject acReport, "rptL2005_02", True
DoCmd.PrintOut acPages, 1, 2

stDocName = "rptT2005_05"
DoCmd.OpenReport stDocName, acPreview
DoCmd.SelectObject acReport, "rptt2005_05", True
DoCmd.PrintOut acPages, 1, 1

There's nothing in your code to loop, and it's not at all clear what you're
looping. What are these reports? What are their recordsources? What are their
recordsources? Why are you using the PrintOut method rather than simply
opening the report in acNormal view to print the entire report?

More info please!
 
A

ap19

There are mulitple queries. I want to print the first 2 pages of
rptL2005_02, then the first page of rptT2005_05". The repeat the cycle for
the rest of the records...approximately 50 of them. Otherwise, I would have
to print the reports seperately and collate them manually.
 
J

John W. Vinson

There are mulitple queries. I want to print the first 2 pages of
rptL2005_02, then the first page of rptT2005_05". The repeat the cycle for
the rest of the records...approximately 50 of them. Otherwise, I would have
to print the reports seperately and collate them manually.

Again:

WE CANNOT SEE YOUR DATABASE.

You have not yet explained what you're looping, or where the records are
coming from, or how the report knows which record to print.

This seems to be a totally backwards way to do this - a single Report with two
Subreports (derived from your two reports here, displaying only the desired
one or two pages) would print the records in the desired order with no looping
and no code at all.
 
A

ap19

Sub Reports will not work in the situtation because of the complicated
reporting structure.. I've thought of doing that. The records are coming for
two different queries. One for rptA and one for rptB. I am not looping
anything yet, I was looking for any ideas on looping that will allow me to
print 2 pages from rptA and 1 page from rptB and continue this cycle until
the last record is printed.
 
J

John W. Vinson

Sub Reports will not work in the situtation because of the complicated
reporting structure.. I've thought of doing that. The records are coming for
two different queries. One for rptA and one for rptB. I am not looping
anything yet, I was looking for any ideas on looping that will allow me to
print 2 pages from rptA and 1 page from rptB and continue this cycle until
the last record is printed.

Well, you'll need to open a Recordset on the table that you're looping and use
code like:

Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("queryname", dbOpenSnapshot)
Do Until rs.EOF
<set your parameters for the reports based on the recordset>
<your open report code>
rs.MoveNext
Loop
 
A

ap19

thanks

John W. Vinson said:
Well, you'll need to open a Recordset on the table that you're looping and use
code like:

Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("queryname", dbOpenSnapshot)
Do Until rs.EOF
<set your parameters for the reports based on the recordset>
<your open report code>
rs.MoveNext
Loop
 
T

toleafs via AccessMonster.com

Thanks for the code...
Would you know why I am getting a " Run Time Error '3061' too few parameters.
Expected 2 with the code.
Dim stDocName As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("qsrcLetter", dbOpenSnapshot)
Set rs = db.OpenRecordset("qsrcCalcTbl_Orgn", dbOpenSnapshot)
Set rs = db.OpenRecordset("qsrcCalcTbl_Firm", dbOpenSnapshot)
Do Until rs.EOF

DoCmd.OpenReport stDocName, acPreview
DoCmd.SelectObject acReport, "rptL2005_02", True
DoCmd.PrintOut acPages, 1, 2
DoCmd.OpenReport stDocName, acPreview
DoCmd.SelectObject acReport, "rptt2005_05", True
DoCmd.PrintOut acPages, 1, 1
rs.MoveNext
Loop
 
J

John W. Vinson

Thanks for the code...
Would you know why I am getting a " Run Time Error '3061' too few parameters.
Expected 2 with the code.
Dim stDocName As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("qsrcLetter", dbOpenSnapshot)
Set rs = db.OpenRecordset("qsrcCalcTbl_Orgn", dbOpenSnapshot)
Set rs = db.OpenRecordset("qsrcCalcTbl_Firm", dbOpenSnapshot)
Do Until rs.EOF

DoCmd.OpenReport stDocName, acPreview
DoCmd.SelectObject acReport, "rptL2005_02", True
DoCmd.PrintOut acPages, 1, 2
DoCmd.OpenReport stDocName, acPreview
DoCmd.SelectObject acReport, "rptt2005_05", True
DoCmd.PrintOut acPages, 1, 1
rs.MoveNext
Loop

Presumably one of the queries needs parameters and doesn't have them. Have you
set a breakpoint and stepped through the code? Which OpenRecordset is causing
the error?

Your code is incorrect though - you're opening a recordset based on
qsrcLetter, and then *DESTROYING AND OVERWRITING* that recordset with one
based on qsrcCalcTbl_Orgn, and then destroying that one too. Your loop will
loop through the Firm recordset, and the other two queries will not be
referenced or used at all. I have no idea what the intent of the three queries
might be.
 
T

toleafs via AccessMonster.com

Thanks
Would it be easier to Loop through the two reports based on the cycle:
2 pages from rptL2005_02 and 1 page from rptt2005_05 until all records are
printed.
Thanks for the code...
Would you know why I am getting a " Run Time Error '3061' too few parameters.
Expected 2 with the code.
Dim stDocName As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("qsrcLetter", dbOpenSnapshot)
Set rs = db.OpenRecordset("qsrcCalcTbl_Orgn", dbOpenSnapshot)
Set rs = db.OpenRecordset("qsrcCalcTbl_Firm", dbOpenSnapshot)
Do Until rs.EOF

DoCmd.OpenReport stDocName, acPreview
DoCmd.SelectObject acReport, "rptL2005_02", True
DoCmd.PrintOut acPages, 1, 2
DoCmd.OpenReport stDocName, acPreview
DoCmd.SelectObject acReport, "rptt2005_05", True
DoCmd.PrintOut acPages, 1, 1
rs.MoveNext
Loop
[quoted text clipped - 15 lines]
rs.MoveNext
Loop
 
J

John W. Vinson

Thanks
Would it be easier to Loop through the two reports based on the cycle:
2 pages from rptL2005_02 and 1 page from rptt2005_05 until all records are
printed.


You can't loop through "a report". A report is an output-only medium.
 

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