Condition Syntax

Klion

Registered User.
Local time
Today, 15:27
Joined
Jul 12, 2004
Messages
16
Need a statement like

If (frmResultsSummary is open) then
DoCmd.Close acForm, "frmResultsSummary"
End if


No clue what syntax is to check if something is open though, tried a few searches with no luck.

-Klion
 
Last edited:
I usually define this little function somewhere in my project:

Code:
Public Function IsOpen(strName As String, Optional intType As AcObjectType = acForm)

'From: Getz, Litwin, Gilbert.  Access 200 Delevoper's Handbook Volume 1: Desktop Edition.  1999, Sybex.
'Returns true if the form is open (loaded)

    IsOpen = (SysCmd(acSysCmdGetObjectState, intType, strName) <> 0)
End Function

Once you've defined this, you can write easy-to-read code like this:

Code:
If IsOpen("MyForm", acForm) Then
    '...
End If

'or

If IsOpen("MyReport", acReport) Then
    '...
End If
 
isFormOpen

If you create a new module and paste in this code:

Code:
Function IsFormOpen(strFormName As String) As Boolean

    IsFormOpen = (SysCmd(acSysCmdGetObjectState, acForm, strFormName) = acObjStateOpen)

End Function

(from ghudson, http://www.access-programmers.co.uk...hlight=isloaded)

then you'll be able to call the function like this:

Code:
If IsFormOpen("form_name") then
    Do_Something
End If
 

Users who are viewing this thread

Back
Top Bottom