Full Version: Checking if a report is already open before opening
UtterAccess Discussion Forums > Microsoft® Access > Access Reports
rdemyan
I'm looking for VBA code to check if a report is already open prior to trying to open it. I've noticed that if a report is already open and the code tries to open it again, that the already open report gets the focus and appears on top of the windows. However, a user may have changed criteria and not realize that a report needs to apparantly be closed before it is opened. Hence, they may not realize that the report they see if for a different set of conditions. So, I guess I need code to check if the report is open and then close it, prior to reopening.

Can the report be refreshed instead of closing and then reopening?

Thanks.
r_cubed
Code to check if ANY (type of) object is open.

CODE
Function IsObjectOpen(strName As String, _
                      Optional intObjectType As Integer = acForm) _
                  As Boolean

    ' intObjectType can be:
    
    '   acTable     (value 0)
    '   acQuery     (value 1)
    '   acForm      (value 2)   Default
    '   acReport    (value 3)
    '   acMacro     (value 4)
    '   acModule    (value 5)
    
    ' Returns True if strName is open, False otherwise.
    On Error Resume Next
    
    IsObjectOpen = (SysCmd(acSysCmdGetObjectState, intObjectType, strName) <> 0)

    If Err <> 0 Then
        IsObjectOpen = False
    End If
    
End Function


Just REQUERY the report, rather than close and reopen
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.