954,535 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to check if form is open

How do I check if a form is open (not only loaded, but also open)

plusplus
Posting Whiz in Training
207 posts since Jul 2007
Reputation Points: 10
Solved Threads: 16
 
How do I check if a form is open (not only loaded, but also open)


What I mean is, I know how to check if it's loaded, but I want to know if it's being shown at this time

plusplus
Posting Whiz in Training
207 posts since Jul 2007
Reputation Points: 10
Solved Threads: 16
 

Hi,

Copy this Function and Pass the form name. If form is loaded and not shown, then it's Visible property will be false, u need to check that:

Private Sub CheckFormStatus(Myform As Form)
    Dim objForm As Form
    Dim FlgLoaded As Boolean
    Dim FlgShown As Boolean
    FlgLoaded = False
    FlgShown = False
    For Each objForm In VB.Forms
        If (Trim(objForm.name) = Trim(Myform.name)) Then
            FlgLoaded = True
            If objForm.Visible Then
                 FlgShown = True
            End If
            Exit For
        End If
    Next
    MsgBox "Load Status: " & FlgLoaded & vbCrLf & "Show Status:" & FlgShown
End Sub


Regards
Veena

QVeen72
Posting Shark
950 posts since Nov 2006
Reputation Points: 84
Solved Threads: 143
 

Thank you , what you are saying is if it's loaded, check if its visible. Works perfectly. What is Trim in the code you gave me? I did it without, is there any reason it's needed?

plusplus
Posting Whiz in Training
207 posts since Jul 2007
Reputation Points: 10
Solved Threads: 16
 

Hi,

If it is for ur Timer Form..(previous thread), then I suggest an alternative solution. When u show the subForm in Modal, Disable the Timer, And Enable the timer In UnLoad event of the subForm. This way u need not check if the form is loaded/visible and all the stuff..

Regards
Veena

QVeen72
Posting Shark
950 posts since Nov 2006
Reputation Points: 84
Solved Threads: 143
 

Hi,

Trim is not necessariy required, but just to be on the safer side, using Trim..

REgards
Veena

QVeen72
Posting Shark
950 posts since Nov 2006
Reputation Points: 84
Solved Threads: 143
 

Thank you so much for that idea. My project is just getting bigger and bigger and every time I add another thing, I have to make sure it doesn't cause any problems to my old stuff. I'm at the end now and trying out every single possibility, to make sure it all works.

plusplus
Posting Whiz in Training
207 posts since Jul 2007
Reputation Points: 10
Solved Threads: 16
 

Just put the following code in your form closing event (for vb.net (VS2008). For more detail http://developerskb.blogspot.com

Private Sub frmMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        If frmOrdDet.Visible = True Then
            MsgBox("Costing detail input form is in active! Close it before exit", MsgBoxStyle.Information)
            frmOrdDet.Focus()
            e.Cancel = True
        Else
            Dim dr As Object
            If e.CloseReason = CloseReason.UserClosing Then
                dr = MsgBox("Exit Application..?", MsgBoxStyle.YesNo Or MsgBoxStyle.Question)
                If dr = vbYes Then
                    frmLogin.Dispose()
                    Me.NotifyIcon.Dispose()
                    e.Cancel = False
                Else
                    e.Cancel = True
                End If
            End If
        End If
    End Sub
arbalu
Newbie Poster
4 posts since Jul 2008
Reputation Points: 10
Solved Threads: 0
 

Thanks ur code worked for me....

Hi, Copy this Function and Pass the form name. If form is loaded and not shown, then it's Visible property will be false, u need to check that:

Private Sub CheckFormStatus(Myform As Form)
    Dim objForm As Form
    Dim FlgLoaded As Boolean
    Dim FlgShown As Boolean
    FlgLoaded = False
    FlgShown = False
    For Each objForm In VB.Forms
        If (Trim(objForm.name) = Trim(Myform.name)) Then
            FlgLoaded = True
            If objForm.Visible Then
                 FlgShown = True
            End If
            Exit For
        End If
    Next
    MsgBox "Load Status: " & FlgLoaded & vbCrLf & "Show Status:" & FlgShown
End Sub

Regards Veena

alaguvadi
Newbie Poster
1 post since Mar 2009
Reputation Points: 10
Solved Threads: 0
 

I don't recall where I found this, but it works:

Public Function fncIsFormOpen(strFormName As String) As Boolean
If (SysCmd(acSysCmdGetObjectState, acForm, strFormName) = acObjStateOpen) Then fncIsFormOpen = True
End Function

muspench
Newbie Poster
1 post since Jan 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You