Open report from form, then wait til report is closed before running rest of code?

  • Thread starter Thread starter Jason Gyetko
  • Start date Start date
J

Jason Gyetko

I have a Sub routine that gets run when a button is clicked, it opens a
report, then does some other things. Right now it opens that report then as
soon as the report is open, it runs the rest of the routine. Is there a way
for it to open the report, then wait until the report is closed before it
runs the rest of the routine? I know I can put the rest of the code in the
OnClose of the report, but I need to keep the code all within the form
because I also open that report from other places where I don't want to run
the routine when the report closes. Thanks.
 
Here's a thought. It's not completely tested. Put this in a general
module:

Sub test()
Dim bolClosed
Dim rpt As Report
bolClosed = False

Debug.Print "A"
Debug.Print "B"
Do Until bolClosed = True
bolClosed = True
For Each rpt In Reports
DoEvents
If rpt.Name = "Authors" Then
bolClosed = False
End If
Next
Loop
Debug.Print "C"
Debug.Print "D"

End Sub

and open several reports. Replace "Authors" above with one of your open
reports, then run the code. It should print A and B, then wait until you
close the report before printing C and D in the immediate window. It's a
start.
 
Back
Top