5
Contributors
9
Replies
12
Views
9 Years
Discussion Span
Last Post by muspench
0

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

0

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

0

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?

0

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

0

Hi,

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

REgards
Veena

0

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.

0

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
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

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.