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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking To See If A Form Is Open

Status
Not open for further replies.

FontanaS

Programmer
May 1, 2001
357
US
Hi,

I want to check to see if a particular form is open when the user clicks on a button and then close it if it is open.

If form open then
close form
end if
 
if you're gonna be closing it anyway, then why not just close it, with some error handling...

private sub blah_onClick()
on error goto err:
docmd.close "formName"
end

err:
exit sub
end sub

Procrastinate Now!
 
Heres a little function you can use to test if a form is open.

Code:
Function fIsLoaded(ByVal strFormName As String) As Integer
'Returns a 0 if form is not open or a -1 if Open
    If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> 0 Then
        If Forms(strFormName).CurrentView <> 0 Then
            fIsLoaded = True
        End If
    End If
End Function

Hope that helps

----------------------------------------
My doctor says that I have a malformed public duty gland and a natural deficiency in moral fibre and that I'm therefore excused from saving universes.
----------------------------------------
 
Here's another way:

If (CurrentProject.AllForms("frmName").IsLoaded) Then DoCmd.Close acForm, "frmName
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top