Click to See Complete Forum and Search --> : How to know if a form has been loaded ?


Francois
September 27th, 1999, 03:09 AM
How can i know if one of the Form of the project has been loaded ?

I tried someting like
If MyForm Is Nothing Then ..
but it dosen't work

Thanks

shanep
September 27th, 1999, 03:42 AM
Are you using MDI forms or MDI child forms? If so, you can cycle through the forms collection to see if a specific form is loaded.

'Here's some sample code
Dim iIndex As Integer

For iIndex = 0 To Forms.Count - 1
If (Forms(iIndex).Name = "frmYourForm") Then
MsgBox Forms(iIndex).Caption
End If
Next iIndex

Ravi Kiran
September 27th, 1999, 04:16 AM
Forms Collection is the best method.

Because VB keeps a global instance of the Form (with the same name ). So -
If MyFormName iS Nothing - will always be false, because there always exists a form by name 'MyFormName'. Typically what people do is not refer this Global form.

You could do something like this also:
dim lpForm as Form
...
set lpForm = New MyFormName
..else where
' check if an instance is loaded:
if lpForm Is nothing then
Set lpForm = New MyFormName
end if
' use the properties ..
lpForm.SomeProperty = SomeValue



RK