View Full Version : Is my form loaded/open?


ajetrumpet
09-13-2009, 08:00 PM
This works on any type of object in the database:

The system command built-in function from MS works wonders. here it is: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:form = 2
function = 10
macro = 4
module = 5
query = 1
report = 3
table = 0

gemma-the-husky
09-16-2009, 01:19 AM
note that vba has constants for the second parameter


so

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

etc etc

boblarson
09-16-2009, 09:27 AM
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
11-17-2009, 01:17 PM
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.