How to Close Reports If Open

  • Thread starter Thread starter doyle60
  • Start date Start date
D

doyle60

I have code that closes down forms if open. I tried to adapt it to a
report but it doesn't seem to work:

If IsOpen("SelfPrintNewrpt01a") Then
DoCmd.Close acReport, "SelfPrintNewrpt01a"
End If

If I remember correctly, Access 95 did not have an IsOpen function and
I had to create a module. But Access 97, which I presently have, does
have one. Anyway, the IsOpen function is working on the forms but not
on reports as above. What to do? Thanks,

Matt
 
I have code that closes down forms if open. I tried to adapt it to a
report but it doesn't seem to work:

If IsOpen("SelfPrintNewrpt01a") Then
DoCmd.Close acReport, "SelfPrintNewrpt01a"
End If

If I remember correctly, Access 95 did not have an IsOpen function and
I had to create a module. But Access 97, which I presently have, does
have one. Anyway, the IsOpen function is working on the forms but not
on reports as above. What to do? Thanks,

Matt

I believe you are thinking of the IsLoaded() function for forms, not
IsOpen().

Why do you need to see if it is open?
Just close it.
DoCmd.Close acReport, "SelfPrintNewrpt01a"
You will not get an error if it is not open.
 
Actually, Access 97 doesn't have an IsOpen function built into it: you must
have a library added to your application (or the function has been defined
in one of your modules)
 
Because I have a situation where as many as nine reports open and all
of them have photographs on them. They are a pain to close down. If I
don't get the error if not open, I'll do it your way. Thanks.

Yes, I do have a module with the IsOpen function in it. But I guess I
didn't find it. It's there, somewhere.

Thanks all,

Matt
 
Because I have a situation where as many as nine reports open and all
of them have photographs on them. They are a pain to close down. If I
don't get the error if not open, I'll do it your way. Thanks.

Yes, I do have a module with the IsOpen function in it. But I guess I
didn't find it. It's there, somewhere.

Thanks all,

Matt

Even if it did throw an error, you can trap it:

On Error GoTo Err_Handler
DoCmd.Close acReport, "SelfPrintNewrpt01a"
Exit_Sub:
Exit Sub
Err_Handler:
If Err = ???? Then
Else
MsgBox "Error #: " & Err.Number & " " & Err.Description
End If
Resume Exit_Sub

Change ???? to whatever the actual error number is.
 
Back
Top