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

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.
 
G

George Nicholson

Jason:

Here is what I use:

(your Form)
DoCmd.OpenReport strReport, acViewPreview
WaitUntilClosed strReport, acReport

(both of the following are in a general module. Note that they will support
objects other than reports)

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

Public Function IsLoaded(strObjName As String, Optional lngObjType As
acObjecttype = acForm) As Boolean
' Returns True if strObjName is Open (non-zero), False(0) otherwise.
' Should return 0, not an error, if the object doesn't exist
' Default Object is Form
On Error Resume Next
IsLoaded = (SysCmd(acSysCmdGetObjectState, lngObjType, strObjName) <> 0)
End Function

HTH,
 
6

'69 Camaro

Hi, Jason.

You could also use the "dialog" window mode of the OpenReport method of
DoCmd:

DoCmd.OpenReport strMyReport, acViewPreview, , , acDialog

While your user has the report open, no code will execute in your button's
subroutine. As soon as your user closes the report, then the line of code
immediately following the above code will execute.

HTH.
Gunny

Coming soon:
For your Microsoft Access, database development and maintenance needs, see:
http://www.softomagixly.com
 
T

tina

quite nice, thanks Jason! :)

-----Original Message-----
Hi, Jason.

You could also use the "dialog" window mode of the OpenReport method of
DoCmd:

DoCmd.OpenReport strMyReport, acViewPreview, , , acDialog

While your user has the report open, no code will execute in your button's
subroutine. As soon as your user closes the report, then the line of code
immediately following the above code will execute.

HTH.
Gunny

Coming soon:
For your Microsoft Access, database development and maintenance needs, see:
http://www.softomagixly.com


that they will
support
 
T

tina

oops, i mean thanks Gunny!

-----Original Message-----
Hi, Jason.

You could also use the "dialog" window mode of the OpenReport method of
DoCmd:

DoCmd.OpenReport strMyReport, acViewPreview, , , acDialog

While your user has the report open, no code will execute in your button's
subroutine. As soon as your user closes the report, then the line of code
immediately following the above code will execute.

HTH.
Gunny

Coming soon:
For your Microsoft Access, database development and maintenance needs, see:
http://www.softomagixly.com


that they will
support
 
J

Jason Gyetko

I don't have the acDialog arguement available with my OpenReport method.

If I try to run it anyway, I get a Compile Error: Wrong number of
arguements or invalid property assignment.
 
D

Dirk Goldgar

Jason Gyetko said:
I don't have the acDialog arguement available with my OpenReport
method.

If I try to run it anyway, I get a Compile Error: Wrong number of
arguements or invalid property assignment.

The WindowMode and OpenArgs arguments were added in Access 2002.
 
J

Jason Gyetko

Thanks, that does the trick.

George Nicholson said:
Jason:

Here is what I use:

(your Form)
DoCmd.OpenReport strReport, acViewPreview
WaitUntilClosed strReport, acReport

(both of the following are in a general module. Note that they will support
objects other than reports)

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

Public Function IsLoaded(strObjName As String, Optional lngObjType As
acObjecttype = acForm) As Boolean
' Returns True if strObjName is Open (non-zero), False(0) otherwise.
' Should return 0, not an error, if the object doesn't exist
' Default Object is Form
On Error Resume Next
IsLoaded = (SysCmd(acSysCmdGetObjectState, lngObjType, strObjName) <> 0)
End Function

HTH,
--
George Nicholson

Remove 'Junk' from return address.


then
 
6

'69 Camaro

Thanks, Dirk!

I forgot that this feature isn't available for reports on earlier versions
of Access. It was available for the OpenForm method of DoCmd in those
versions, though.

Gunny
 
D

Dirk Goldgar

'69 Camaro said:
I forgot that this feature isn't available for reports on earlier
versions of Access. It was available for the OpenForm method of
DoCmd in those versions, though.

Quite right. It was a much-needed addition. Unfortunately, by using it
we lock ourselves into code that isn't backward compatible, and there
are lots of A2K and A97 shops out there still. So I tend to avoid it
except in applications tailored to a specific customer.
 

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