Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to tell if a form is open?

Status
Not open for further replies.

iainm

Technical User
Nov 28, 2001
67
0
0
AU
Can anyone tell me how to tell if a given form is open in code? Was thinking there may be something like an IsOpen property, but that would give you an error if the form was closed. Is there a method that will accept a form name and return true if the form is open, like IsOpen(formname)? What I want to do with it is
IF form is open THEN
statements
ELSE
more statements
ENDIF

Alternatively, perhaps someone has a different solution to my entire problem. What I'm using this for is a toggle button to open or close a form (filter) from a button on another form (main). If filter is closed, the button label on main says "show filters" and if it is open the button shows "hide filters". This'll need to be done in OnOpen and OnClose form events in filter, as the user can close the filter form manually as well as using the button. The button code needs to decide whether to try and open or close the form. I could do it with error trapping - try to close the form, and if you get an error, open it instead, but that's dodgy programming practice. Any better ideas?
-Iainm
 
Iainm,

Use the following code in Access2K:

If CurrentProject.AllForms("frmYourForm").IsLoaded Then
........
Else
........
EndIf

Cheers,

Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
 
In addition to Steve's suggestion, you can also use the SysCmd Method. The SysCmd Method returns:

0 if the form isn't open or doesn't exist
1 if the form is open
2 if the form was changed but not saved
4 if the form is new

Any combination of the above for those that are true

Here's an example:

If SysCmd(acSysCmdGetObjectState, acForm, formname) <> 0
form is open statements
Else
form is not open statements
End If
dz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top