I know there is an easy way to do this, to check if a form is loaded without loading it. Because when i try
If Form2.visible = True Then
then it loads the form.
Printable View
I know there is an easy way to do this, to check if a form is loaded without loading it. Because when i try
If Form2.visible = True Then
then it loads the form.
Try this
:wave:Code:If Form2 Is Nothing Then
Load Form2
End If
If Form2 exists, it will never be nothing.
There are a couple ways to do this
1. When Form2 loads, have it set a public variable either in your main form or in a bas module & reset it when it unloads
2. Add this to your Form2
Code:Public isLoaded As Boolean
Private Sub Form_Load()
isLoaded = True
End Sub
Private Sub Form_Unload(Cancel As Integer)
isLoaded = False
End Sub
' Now from any code, you can check via: Form2.isLoaded = True
Use the forms collection to checkCode:Private Sub Command1_Click()
Dim frm As Form
Dim blnLoaded As Boolean
For Each frm In Forms
If frm.Name = "Form2" Then
blnLoaded = True
End If
Next frm
MsgBox "Form2 is loaded = " & blnLoaded
End Sub
Private Sub Command2_Click()
Load Form2
End Sub