Is my form loaded/open? (1 Viewer)

Status
Not open for further replies.

ajetrumpet

Banned
Local time
Today, 15:30
Joined
Jun 22, 2007
Messages
5,640
Is my form loaded/open? (VBA check)

This works on any type of object in the database:

The system command built-in function from MS works wonders. here it is:
PHP:
Function GetObjState(strName String, strType As Long) As String

dim ObjState as long

ObjState = SysCmd(acSysCmdGetObjectState, strType, strName)

    if ObjState = 0 then 
       ' The object is closed.
        GetObjState = "Closed"
    
elseif ObjState = 1 then 
       ' The object is open.
        GetObjState = "Open"

elseif ObjState = 2 then 
       ' The object has been modified
        GetObjState = "Modified and UnSaved"

    end if

msgbox GetObjState

end function
Here are the object types for the second argument:
PHP:
form = 2
function = 10
macro = 4
module = 5
query = 1
report = 3
table = 0
 
Last edited:

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 21:30
Joined
Sep 12, 2006
Messages
13,892
note that vba has constants for the second parameter


so

getobjstate("myform", acform)
getobjstate("myquery", acquery)

etc etc
 

boblarson

Smeghead
Local time
Today, 13:30
Joined
Jan 12, 2001
Messages
32,068
For most situations you don't need this code. If a form is Loaded (in Access) it is open. And therefore you can use the

CurrentProject.AllForms.IsLoaded("formNameHere")

to get the true or false as to whether it is loaded. Most of the time you do not need to know if a form/report is modifed/unsaved as we don't normally do runtime changes to design (especially with an MDE/ACCDE as you can't).

So, while this code may work, it is certainly overkill in most circumstances.
 

liannagreyson

New member
Local time
Today, 13:30
Joined
Nov 17, 2009
Messages
1
Very nice post with a ton of informative information. I really appreciate the fact that you approach these topics from a stand point of knowledge and information
instead of the typical “I think” mentality that you see so much on the internet these days.
 
Last edited:
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top Bottom