Print Command button question...

C

cathywoodford

Hi. I have a print preview button that is on about 22 forms. I was
wondering is there a way to declare this code globally so that I don't
have to code each one separately. Trick being that each one has to
open with a different report template. For example if the user is on
form1 then when he/she clicks the print button it has to be viewed in
report1, but if they are on form2 and click the button it must be
viewed in report2. Is this possible?

Thanks,
Cathy
 
B

Barry Gilbert

It won't save you too much code, but you could do something like this:

In a module, put this procedure:

Public Sub PrintPreviewReport(ByVal reportName As String, ByVal filterName
aAs String, ByVal whereCondition As String, ByVal windowMode As acWindowMode,
ByVal openArgs As String)
DoCd.OpenReport reportName, acViewPreview, filterName, whereCondition,
windowMode, openArgs
End Sub

The only thing this saves is having to specify the acView parameter.
However, you can leave out parameters if, for example, you never use the
filterName parameter.

Barry
 
F

fredg

Hi. I have a print preview button that is on about 22 forms. I was
wondering is there a way to declare this code globally so that I don't
have to code each one separately. Trick being that each one has to
open with a different report template. For example if the user is on
form1 then when he/she clicks the print button it has to be viewed in
report1, but if they are on form2 and click the button it must be
viewed in report2. Is this possible?

Thanks,
Cathy

You can, however I don't see much benefit.

Create a New Module.
Sub OpenReports(rptName as String)
DoCmd.OpenReport rptName, acViewPreview
End Sub

Code the command button on each form:
OpenReports "NameOfReportToOpen"
 
Top