Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple Instances of a Report

Status
Not open for further replies.

jeff5311

Programmer
Mar 1, 2002
31
US
Does anyone know how to open multiple instances of the same report?

I have a report named: rptPOs

I need open multiple instances of the report at one time (so the user will know to print ALL instances of the report).

I'm trying to open each report each report passing different filter criteria using:

DoCmd.OpenReport "rptPOs", acPreview, , stLinkCriteria

Which of course, does not seem to work.

Can anyone help?

Thanks,
Jeff
 
Jeff,

Why not run the the same report multiple times with different criteria serially (as opposed to multiple instances in parallel)? I would have thought this was a simpler solution; for example:

DoCmd.OpenReport "Report1", acViewNormal, , WhereCond1
DoCmd.OpenReport "Report1", acViewNormal, , WhereCond2
DoCmd.OpenReport "Report1", acViewNormal, , WhereCond3

The only thing thats variable above is the Where condition which you can set up before any of the printing, or between each Docmd.openreport command.

I think that the above approach should work fine providing you dont wish to preview the reports. If you do, you will need to add some code between each docmd.openreport command to prevent the program from continuing once the preview window is opened. I use a global function which I call "ang_Ten", defined as follows:

Public Function HangTen(Con)
'-----------------------------------------------
'Wait around until the current object is closed.
'-----------------------------------------------
While Application.CurrentObjectName = Con
DoEvents
Wend

End Function

Thus for example, if your report is called rptYourReport, then your code might look like this:

WhereCond1 = "CustType = 'Local'"
WhereCond2 = "CustType = 'Australian'"
WhereCond3 = "ColorOfEyes = 'Green'"

rptName = "rptYourReport"

DoCmd.OpenReport rptName, acViewNormal, , WhereCond1
x = Hang_Ten(rptName)
DoCmd.OpenReport rptName, acViewNormal, , WhereCond2
x = Hang_Ten(rptName)
DoCmd.OpenReport rptName, acViewNormal, , WhereCond3
x = Hang_Ten(rptName)
...etc...

I'm aware that I hav'nt exactly answered your question, but I do hope that this will provide a simpler way to solve your problem. Let me know,

Cheers,

Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
 
If you like, you can open multiple instances of a form or report by opening it as an object. You'll have to set the properties yourself, as there are no parameters in the constructor in VBA.

example to open two reports:

dim rtp1 as Report_rptPOs
dim rtp2 as Report_rptPOs
set rpt1=new Report_rptPOs
set rpt2=new Report_rptPOs
rpt1.visible=true
rpt2.visible=true

I do not know if you have the chance to set the filter criteria after the creation. You might have to use a global variable for that and set the filter in an open event (yuk).
 
Hey guys! Thanks for your input... I was able to figure it out. Here's what I did:

1) Declare a global variable (in the module header, outside of the subroutine) like this:

'Assume we'll never need more than 25 instances of the
'same report open at once
Dim rpt(1 To 25) As Report

2) set a member of the global array equal to the specific instance, filter according to whatever criteria you'd like, and make the instance visible.

'open rptPOs in separate windows
Set rpt(i) = New Report_rptPOs
rpt(i).Filter = stLinkCriteria
rpt(i).Visible = True

that's it! it works like a champ!

Though I hate having to assume a maximum size for the array (not a good coding practice), it was the only way I could get it to work.

Thanks Again,
Jeff
 
Hi Jeff,
Glad you solved the problem. Could you please tell me why you're opting for the multi instance solution. I do see the (possible) benefit of being able to preview the different reports simultaniously on-line; is there some other reason as wel? For me, the serial print-close loop provides a simpler system and customer interface, but I may be missing the point here. I'd appreciate your reason for this approach;
Cheers,

Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
 
Steve,

Your right, the serial print probably would work, especially if I were sending the reports directly to the printer.

I guess I was trying to open each report in "Preview Mode" in parallel so they each could be faxed or sent to a different printer individually (specify the printer/fax before printing). Does this make sense?

Thanks Again,
Jeff

 
Yes, its one approach Jeff, but my approach for that requirement would still be serial; eg. assuming there are 10 different reports, each with different filter criteria, and each with a possibly different destination printer. I would hold the filter information AND the destination information in a related table, and then iterate through the table as follows (pseudo code only; assume that the filter is Department related)

For each Department
Build the FilterCriteria
Determine the DepartmentPrinter
Build and Send the report based on the FilterCriteria
to the DepartmentPrinter
Next Department

In the above example, you might for example hold the Department Head's email address, so that you could send the report directly as an attachment to the department representative.

Food for thought?

Good luck, Cheers,

Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
 
Steve,

Yep! That certainly makes sense... only I don't have the destination printers (they can be local printers, network printers, "non-standard" faxing software, etc...), and as you can imagine, each user's machine can have different printers. So it's easier in my case to just pull them all up and let the user decide where they should go.

But I do like your serial solution for mass-printing. However, instead of writing a procedure for hanging and waiting and declaring all those variables, couldn't you just specify that the report be opened/printed "modally" (or in a "pop-up") and loop through each report. Like this:

assume the report is modal:

'get set of all rpts you'd like to print (any code you'd like)

do while not rptPOs!EOF

'set report criteria (any code you'd like)

'set report name (and code you'd like)

DoCmd.OpenReport rptName, acViewNormal, , stLinkCriteria

'reset report criteria and name
rptName = ""
stLinkCriteria = ""

loop

I've never done this, but it seems it would spool each report modally (serially) -- you wouldn't have to write a "wait" function and declare extra variable (or ever run out of variables).

But I guess there's more than one way to skin this cat!

Thanks again for your help!!!
Jeff
 
Jeff,
I'm not aware that a report can be treated 'modally' like a form. Once rendered in preview mode, the little Access engine keeps chundering along in the background with its next line of code; before you know it, you've got n open report windows staring you in the face, and then typically the modal User Interface form pops up (literally) to cause more confusion.
Thats why I put in the wait routine. Perhaps there is a property that I'm missing, and there is an easier way to do it, but like I say, I'm not aware of it. Havnt got Access available on this machine to check right now.
Cheers,

Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top