Is Form Open

GregSmith

Registered User.
Local time
Today, 09:46
Joined
Feb 22, 2002
Messages
126
How do you tell if a form is open or not?
I have a main form that when a user selects a command button, will open another form. From the new form - it may open a 3rd form.

I would like to close the 2nd form after the 3rd form opened up.

Any idea??
 
use this in your "OnLoad" event of 3rd form:

If SysCmd(acSysCmdGetObjectState, acForm, "2nd Form Name") <> 0 Then
DoCmd.Close acForm, "2nd Form Name"
End If

Im using access2002, not sure if SysCmd is supported in all versions
 
or slightly better:
Code:
If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> 0 Then
    If Forms(strFormName).CurrentView <> 0 Then
        IsLoaded = True
    End If
End If
This is also handy with reports and forms:
Code:
Public Sub Suspend(ByVal sName As String, Optional ByVal CheckBoth As Byte = 0)
'suspends code until opened form/report has been closed
Dim hwnd As Long

On Error Resume Next

Select Case CheckBoth
    Case 1:     ' Form Only
        hwnd = Forms(sName).hwnd
    Case 2:     ' Rep Only
        hwnd = Reports(sName).hwnd
    Case Else
        hwnd = Forms(sName).hwnd
        If hwnd = 0 Then hwnd = Reports(sName).hwnd
End Select

While IsWindow(hwnd)
    DoEvents
Wend
End Sub
 
Suprised no one else posted this. It is copied straight from NorthWind

Copy to a Module:

Function IsLoaded(ByVal strFormName As String) As Boolean

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


‘Called from Form:

‘If IsLoaded("frmName") Then

‘End If

Dave
 
heh? I did post it!! :) ok it was only the core of the function but hey it was early :D
 

Users who are viewing this thread

Back
Top Bottom