Is Form Open (1 Viewer)

GregSmith

Registered User.
Local time
Today, 17:43
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??
 

jfgambit

Kinetic Card Dealer
Local time
Today, 23:43
Joined
Jul 18, 2002
Messages
798
What version of Access are you using?
 

sukhi

Registered User.
Local time
Today, 23:43
Joined
May 1, 2004
Messages
10
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
 

cable

Access For My Sins
Local time
Today, 23:43
Joined
Mar 11, 2002
Messages
228
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
 

Oldsoftboss

AWF VIP
Local time
Tomorrow, 08:43
Joined
Oct 28, 2001
Messages
2,499
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
 

cable

Access For My Sins
Local time
Today, 23:43
Joined
Mar 11, 2002
Messages
228
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

Top Bottom