tell if a form is open

G

geebee

Hi,

I want to be able to write code to evaluate whether or
not a form is open. For example, if form A is open,
perform a certain action, else, perform another action.

Does anyone know the code to do this. I have run into
several snippets of code, but can't really interpret them.

Thanks in advance,
geebee
 
S

Sandra Daigle

Try the following function:

if isloaded("form1") then
msgbox "Form1 is loaded"
endif

Public Function IsLoaded(ByVal strFormName As String) As Integer
Const conObjStateClosed = 0
Const conDesignView = 0
If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <>
conObjStateClosed Then
If Forms(strFormName).CurrentView <> conDesignView Then
IsLoaded = True
End If
End If
End Function

Or in Access 2000 and above you can test the AllForms collection of the
CurrentProject object.

if CurrentProject.allforms("form1").isloaded then
msgbox "Form1 is loaded"
endif
 
V

Van T. Dinh

If you use A2K or later, you can also use:

CurrentProject.AllForms("FormName").IsLoaded

to check whether the Form is open or not.
 
G

geebee

HI,

Thanks for your response. I am not sure where to put the
folowing code you recommended:

Public Function IsLoaded(ByVal strFormName As String) As
Integer
Const conObjStateClosed = 0
Const conDesignView = 0
If SysCmd(acSysCmdGetObjectState, acForm,
strFormName) <>
conObjStateClosed Then
If Forms(strFormName).CurrentView <>
conDesignView Then
IsLoaded = True
End If
End If
End Function



Thanks in advance,
geebee
-----Original Message-----
Try the following function:

if isloaded("form1") then
msgbox "Form1 is loaded"
endif

Public Function IsLoaded(ByVal strFormName As String) As Integer
Const conObjStateClosed = 0
Const conDesignView = 0
If SysCmd(acSysCmdGetObjectState, acForm,
strFormName) said:
conObjStateClosed Then
If Forms(strFormName).CurrentView <> conDesignView Then
IsLoaded = True
End If
End If
End Function

Or in Access 2000 and above you can test the AllForms collection of the
CurrentProject object.

if CurrentProject.allforms("form1").isloaded then
msgbox "Form1 is loaded"
endif

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.
Hi,

I want to be able to write code to evaluate whether or
not a form is open. For example, if form A is open,
perform a certain action, else, perform another action.

Does anyone know the code to do this. I have run into
several snippets of code, but can't really interpret them.

Thanks in advance,
geebee
.
 
S

Sandra Daigle

Hi Geebee,

Put it in a standard module - from the database window view modules and then
click new.


--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.

HI,

Thanks for your response. I am not sure where to put the
folowing code you recommended:

Public Function IsLoaded(ByVal strFormName As String) As
Integer
Const conObjStateClosed = 0
Const conDesignView = 0
If SysCmd(acSysCmdGetObjectState, acForm,
strFormName) <>
conObjStateClosed Then
If Forms(strFormName).CurrentView <>
conDesignView Then
IsLoaded = True
End If
End If
End Function



Thanks in advance,
geebee
-----Original Message-----
Try the following function:

if isloaded("form1") then
msgbox "Form1 is loaded"
endif

Public Function IsLoaded(ByVal strFormName As String) As Integer
Const conObjStateClosed = 0
Const conDesignView = 0
If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <>
conObjStateClosed Then
If Forms(strFormName).CurrentView <> conDesignView Then
IsLoaded = True
End If
End If
End Function

Or in Access 2000 and above you can test the AllForms collection of
the CurrentProject object.

if CurrentProject.allforms("form1").isloaded then
msgbox "Form1 is loaded"
endif

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.
Hi,

I want to be able to write code to evaluate whether or
not a form is open. For example, if form A is open,
perform a certain action, else, perform another action.

Does anyone know the code to do this. I have run into
several snippets of code, but can't really interpret them.

Thanks in advance,
geebee
.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top