Printing Multiple Reports

SteveF

Registered User.
Local time
Today, 18:52
Joined
Jul 13, 2008
Messages
218
Hi Guys, I wonder if someone could point me right?

I have several reports that I would like to print one after the other, is there any way I can do this? The way I have the menu set up at the moment is with simple command buttons to either preview or print each separate report, is it possible to have check boxes by the side of reports so I can just tick the ones I want and print once? I tried grouping options but couldn't fathom how they work.

Thanks in advance.
 
For grouping the selected reports and have them printed 1 after the other u might:
1. Create a dynamic array and the loop through it to print;
2. Create a temporary table, populate it with the selected reports, then print by looping through the records in that temp table.

The working of Dynamic Arrays are harder to explain, so for now I'll stick with the temp table approach:

Put this code in your Form_Load Event to create the temp table:

Private Sub CreateTable()
Dim db As dao.Database
Dim tbl As dao.TableDef
Dim fld As dao.Field
'Point the Database object at a reference to the current database
Set db = CurrentDb()
DoCmd.SetWarnings False
'Point a TableDef object at a new TableDef
Set tbl = db.CreateTableDef("tblPrintReports")

'Add a field to the TableDef object
Set fld = tbl.CreateField("ReportName", dbText, 25)
tbl.Fields.Append fld
DoCmd.SetWarnings True
End Sub

Every time u load the form the former temp table will be replaced by a new empty one.

Create the following sub to populate the table:

Private Sub PopulatePrintReportsTable(rptName As String)
Dim db As DAO.Database
Dim rs As DAO.Recordset

Set db = CurrentDB()
Set rs = db.OpenRecordset("tblPrintReports", dbOpenDynaset)

rs.AddNew
!ReportName = rptName
rs.Update
rs.close
End Sub


I assume u have seperate buttons to print the diferent reports, say btnPrint1 prints report1, btnPrint2 prints report2 and so on??
Now let's take a look at the code for btnPrint1:

Private Sub btnPrint1_Click()
PopulatePrintReportsTable("report1")
End Sub

This will call Procedure PopulatePrintReportsTable and cause it to add the name "report1" to the temp table.

The other buttons are coded likewise. So every button u click will not yet print the report but just add the name of the corresponding report to the temp table. I suggest u change the caption on the buttons to something like "Select for Print".

Now u should create an extra button saying something like "Print Selected" and code it as follows:

Private Sub btnPrintSelected_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim rptName As String
Set db = CurrentDB()
Set rs = db.OpenRecordset("tblPrintReports", dbOpenDynaset)

do until rs.EOF
rptName = rs!ReportName
DoCmd.OpenReport rptName, acViewNormal
rs.MoveNext
Loop
rs.close
End Sub

This code will loop thru all the report names added to the temp table and print them 1 after the other, in the order they were added.

To prevent users from accidentally selecting a report more than once u might change the print buttons codes to:

Private Sub btnPrint1_Click()
PopulatePrintReportsTable("report1")
Me.btnPrintSelected.SetFocus
Me.btnPrint1.enabled = false
End Sub

After printing u might enable them back by adding the following lines at the end of btnPrintSelected_Click

Me.btnPrint1.enabled = true
Me.btnPrint2.enabled = true
....

Have fun and HTH
 
Holy smoke! Thanks for the answer, it's going to take me a while to get my head around all that though.

The brilliant thing about Access is that it does most of the work for you, I'm pretty much totally 'code ignorant', so when something tricky like this comes along it takes me some time to work it through.
 

Users who are viewing this thread

Back
Top Bottom