CodeItBetter Programming Another VB Programming Blog

How to check whether a Form is already loaded

Posted on January 5, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
'Forms - How to check whether a Form is already loaded

Option Explicit
 
'Add two Command Buttons to your form. Add Another Form (Form 2).
'The first one is to detect whether Form2 is loaded or not
'the second button is to load Form2

Public Function FormLoadedByName(FormName As String) As Boolean
    Dim I As Integer, fNamelc As String
    fNamelc = LCase$(FormName)
    FormLoadedByName = False
    For I = 0 To Forms.Count - 1
        If LCase$(Forms(I).Name) = fNamelc Then
            FormLoadedByName = True
            Exit Function
        End If
    Next I
End Function
 
Private Sub Command1_Click()
    If FormLoadedByName("Form2") = True Then
        MsgBox "The Form is loaded"
    Else
        MsgBox "The Form is not loaded"
    End If
End Sub
 
Private Sub Command2_Click()
    Load Form2
End Sub
Filed under: Forms Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.