check if form is open

Sohotra

Registered User.
Local time
Today, 03:32
Joined
Jan 6, 2007
Messages
21
How do you check in Form_B if Form_A is open?
 
IsLoaded

Here is the function that I use.

Code:
Function IsLoaded(ByVal strFormName As String) As Integer
'======================================
'Returns True if the specified form is open in Form view or Datasheet view.
'Test to make sur that a form is open (IsLoaded) before a procedure is run.
'======================================
On Error GoTo ErrHandler

    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

Exit Function
ErrHandler:
        MsgBox "Error: " & Err.Number & " - " & Err.Description, vbInformation, "Opps Error"
    Exit Function
End Function

So you call it at an event, like...

Code:
Sub btnClose_Click()
If IsLoaded("YOUR FORM NAME") Then
Do something here
End If 
etc...

Hope that helps :)
 
That did the trick!
Thankyou very much
 
I have been trying to get this to work, but I think I am doing something wrong. I have taken the 1st code and placed it into a module so that I can use it by calling the "IsLoaded" function. I placed a button on a form with the 2nd set of coding and i get the error:

"Compile Error: Ambiguous name detected: IsLoaded"

What am I doing wrong? Can I not have this in a module?

Edit:

Here is the code I have put on the button click of the form.
Code:
Private Sub Command112_Click()
If IsLoaded("Provider Letters") Then
MsgBox "New Provider Letter form is loaded", vbInformation, "NLF - Open..."
'Else:
'MsgBox "New Prov Letter form is not loaded", vbCritical, "NPL - Closed..."
End If
End Sub

I named the module "frmLoaded"
 
re:

Hi,
if you are using Acc2000 or higher you don't really need a UDF anymore. All you need is:

If CurrentProject.AllForms("YourForm").IsLoaded Then
...

HTH
Good luck
 
That worked perfectly and is MUCH easier. :) Thanks for the help and the quick response.
 
re:

No problem...glad you got it sorted out.
Good luck on future projects!
 

Users who are viewing this thread

Back
Top Bottom