Previewing more than one report from code

D

Dale

Hi all and thanks for any help with this.
I can't seem to get this code to show more than one report in preview.
There are 18 owners so there should be report previews? I believe the code
is working:
1) The debug window shows 18 instances of owners
2) All18 reports are sent directly to the printer if I leave "acPreview"
blank.

I however want to preview the reports before printing. Code as follows
produces in preview only the very first owner:

Dim dbs As Database, rst As Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblOwners")
rst.MoveFirst
Do Until rst.EOF
Debug.Print rst!Owner
DoCmd.OpenReport "rptValidationtest", acPreview, , "[Owner] = '" &
rst!Owner & "'"
rst.MoveNext

Loop

rst.Close
Set dbs = Nothing
 
D

Dennis

You only get 1 preview because it is the data that changes on the report
according to the owner but not the report name. If you try and print preview
a report will the same file name as one that is already print previewed, it
will simply make the window active.
 
D

Dale

Thanks Dennis...I'm onto a different solution!


Dennis said:
You only get 1 preview because it is the data that changes on the report
according to the owner but not the report name. If you try and print
preview
a report will the same file name as one that is already print previewed,
it
will simply make the window active.

Dale said:
Hi all and thanks for any help with this.
I can't seem to get this code to show more than one report in preview.
There are 18 owners so there should be report previews? I believe the
code
is working:
1) The debug window shows 18 instances of owners
2) All18 reports are sent directly to the printer if I leave "acPreview"
blank.

I however want to preview the reports before printing. Code as follows
produces in preview only the very first owner:

Dim dbs As Database, rst As Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblOwners")
rst.MoveFirst
Do Until rst.EOF
Debug.Print rst!Owner
DoCmd.OpenReport "rptValidationtest", acPreview, , "[Owner] = '" &
rst!Owner & "'"
rst.MoveNext

Loop

rst.Close
Set dbs = Nothing
 
Top