Report opened to preview in program

G

Guest

I have a program that automatically opens a report after generating the
information.
The report is opened for preview and works fine at this point. However the
program is not done yet. I want to give the user the ability to look at the
report and decide if s/he wants to print it, but then how do I get back to my
program after the report is closed?
In my code I do the "docmd.openreport("..."),acpreview" thing and then on
the next line I want to open another form from where the user can either
print the report, run another calculation, or exit the program.
At present the form opens over the report blocking it from view.
Is there a way to pause the program until after the user closes the report
preview?
Thanks,
Joe
 
G

George Nicholson

One approach:

**** Add these 2 functions to a General code module (i.e., not a Form or
Report module)

Public Function IsLoaded(strObjName As String, Optional lngObjType As
acObjecttype = acForm) As Boolean
' Returns True (non-zero) if strObjName is Open, False(0) if not Open or
doesn't exist.
' (subform status can't be tested this way)
'
' The 12 legal acObjectTypes include: acForm (default), acTable,
acQuery, acReport (see ObjectBrowser for complete list)

On Error Resume Next
IsLoaded = (SysCmd(acSysCmdGetObjectState, lngObjType, strObjName) <> 0)
End Function

Public Sub WaitUntilClosed(strObjName As String, Optional lngObjType As
acObjecttype = acForm)
' Suspends code execution while object is open. Default object is a
Form.
On Error Resume Next
Do While IsLoaded(strObjName, lngObjType)
DoEvents
Loop
End Sub

*******
Then, in your code:

Dim strReportName as string

strReportName = "MyReport"
DoCmd.OpenReport strReportName, acViewPreview
Call WaitUntilClosed(strReportName, acReport)
Docmd.OpenForm "someForm"


HTH,
 
G

Guest

Sir,
Thank you Very Much!
Joe

George Nicholson said:
One approach:

**** Add these 2 functions to a General code module (i.e., not a Form or
Report module)

Public Function IsLoaded(strObjName As String, Optional lngObjType As
acObjecttype = acForm) As Boolean
' Returns True (non-zero) if strObjName is Open, False(0) if not Open or
doesn't exist.
' (subform status can't be tested this way)
'
' The 12 legal acObjectTypes include: acForm (default), acTable,
acQuery, acReport (see ObjectBrowser for complete list)

On Error Resume Next
IsLoaded = (SysCmd(acSysCmdGetObjectState, lngObjType, strObjName) <> 0)
End Function

Public Sub WaitUntilClosed(strObjName As String, Optional lngObjType As
acObjecttype = acForm)
' Suspends code execution while object is open. Default object is a
Form.
On Error Resume Next
Do While IsLoaded(strObjName, lngObjType)
DoEvents
Loop
End Sub

*******
Then, in your code:

Dim strReportName as string

strReportName = "MyReport"
DoCmd.OpenReport strReportName, acViewPreview
Call WaitUntilClosed(strReportName, acReport)
Docmd.OpenForm "someForm"


HTH,
 

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