How do I...?

  • Thread starter Thread starter DubboPete
  • Start date Start date
D

DubboPete

Hi all,

I want to be able to check if a form is open, aka 'IsLoaded', but I don't
know how to create the basic function.

This is the (dodgy) code I want to use in A97, and I need to create the
function cos it tells me that sub or function not defined etc:

If IsLoaded(Forms!ActivityReport) Then
Forms!ActivityReport.Visible = False
End If

but I don't know how to create the function!!! I guess this is simple to
some people, but I have never had a need to implement it before now, and I
aint got a clue.

Those module things are scary, so I stay away from that area.......

thanks in advance

DubboPete
 
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
 
Thanks Sandra,

That works absolutely wonderfully, and am using it. However, I have to
paste the function into each form's code, as I don't know where to put it so
it works for any form. Is there a global area I can use it, and if so, how
do I get there? Like I said, this stuff is Twilight Zone for me :-)

Pete
 
Hi Pete,

Put the code into a standard module and then it will be accessible by all
modules (forms, reports, etc.). To create a standard module, go to the
modules section in the database window and click new. You can also do this
from the Visual Basic Editor - Click Insert-->Module.
 
Hi Sandra
Followed your instructions, and when I tried to open a form (and hide
another), I got this message...

Compile Error:
Expected variable or procedure, not module.

Any clues please?

Pete
 
Did you name the module "IsLoaded"? The module can not have the same name as
any function or procedure.
 
Sandra Daigle said:
Did you name the module "IsLoaded"?

and the 17th-century goat-herder replied:
"of course I did, silly!"

and quickly ran off to tend his goats, and change the module name...


DubboPete
 
Back
Top