Send Reports based on Query to Printer Automatically

J

Jeff Byrd

I have a report that I would like to send one at a time to a printer for
each record in a query.

The reason not to print it as one report is that our printer will fold the
individaul reports saving our staff time.

Here is the code I have so far for looping through the query. I am stuck
with how to send the individual reports to the printer.

Function PrintReport()

Dim intRecordCount As Integer
Dim stDocName As String

stDocName = "Printtest"

'Delcale and instantiate a recordset object
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset

'Open a recordset based on the result of the query
rst.Open "qryPrinttest", CurrentProject.Connection
intRecordCount = 0

'' Open report here???
Set mobjCurrentReport = stDocName


Do Until rst.EOF





intRecordCount = intRecordCount + 1

rst.MoveNext

Loop


End Function

Any help is appreciated.
 
T

tina

probably you don't need to print the report again and again. have you tried
putting a page break in the Detail section of the report, so that you get a
separate page for each record in the underlying query?

hth
 
J

Jeff Byrd

We currently have the report set up like that. We need to send it one at a
time becuase that is the only way the printer will fold each report.

tina said:
probably you don't need to print the report again and again. have you
tried
putting a page break in the Detail section of the report, so that you get
a
separate page for each record in the underlying query?

hth
 
T

tina

hmm, okay. you can open the report from a command button on a form, and add
looping code after the OpenReport command to print out each page. of course
it runs very fast, but i take it that the key issue is sending separate
print requests to the printer, regardless of speed?

you'll need to run a DCount function on the query that the report is based
on, to get an accurate recordcount for the loop. see the example below,
which i tested on a table (rather than a query, but it will work the same)
with 5 records in it.

Private Sub cmdPrint_Click()

Dim i As Integer, cnt As Integer

cnt = DCount(1, "tblCustomers")

DoCmd.OpenReport "rptCustomers", acViewPreview
For i = 1 To cnt
DoCmd.PrintOut acPages, i, i
Next

End Sub

the key here is opening the report in Preview, and then running the loop,
because the PrintOut action acts on the *active* object, which will be the
report just opened (unless your form is Modal, in which case you'll need to
set the form's Visible property to No before opening the report). if the
system doesn't identify the report as the active object for some reason, try
adding a SelectObject action after the OpenReport action (and before the
loop).

if you want the report to close once the print requests have gone to the
printer, just add a Close action after the loop, specifying the report
(otherwise you'll close the form instead).

hth


Jeff Byrd said:
We currently have the report set up like that. We need to send it one at a
time becuase that is the only way the printer will fold each report.
 
J

Jeff Byrd

The individaul reports are multi page. This worsk to send each page
individually but I need to send each report individually. Anu Ideas?

Tahnk you for your help.
 
T

tina

nope. good luck with it.


Jeff Byrd said:
The individaul reports are multi page. This worsk to send each page
individually but I need to send each report individually. Anu Ideas?

Tahnk you for your help.
 

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