Determine if a form is loaded without triggering the Form_Load event of that form

mikey
09-01-2003, 09:44 AM
Say you have a form, Form2 that can be called directly from a menu or alternatively from another form, Form1 (in this case it is called modally with Form1 as the owner of Form2).

In the Form_Load event of Form2 I want to determine where its been called from - in particular, if it has been called from Form1.

The following have been tried..

1) Querying Form1.Visible - It seems to attempt to load Form1 (obviously to poll this property) and although it does not show the form it does run part the Form_Load event of Form1 - which I don't want - I simply want to know if it's loaded or not.

2) Querying Me.Owner/Parent - No such properties.

3) "IsNull (Form1)" always returns False.
4) "Form1 Is Nothing" always returns False.

Any ideas? (other than declaring global variables to track them)

P/s - I suppose this is a wake-up call about the programming slackness inadvertently encouraged by the non-strictness of VB, as other truly object-oriented languages such as C++ would no doubt require you to create, manage and destroy individual instances of all objects loaded into memory at run time - including Forms thereby making problems such as this very intuitive to solve.

Volte
09-01-2003, 09:58 AM
You could create a public property of the second form which allows storage of a Owner manually. For example, in the second form:Private m_Owner As Form

Public Property Get Owner() As Form
Owner = m_Owner
End Property
Public Property Set Owner(value As Form)
Set m_Owner = value
End Property

Private Sub Form_Load()
If Not m_Owner Is Nothing Then
MsgBox "The owner of this form is " & m_Owner.Name
End If
End SubAnd in the first:Private Sub Command1_Click()
Set Form2.Owner = Me
Form2.Show vbModel, Me
End SubIt should say "The owner of this form is Form1" when you load the second form.

mikey
09-01-2003, 12:26 PM
You could create a public property of the second form which allows storage of a Owner manually. For example, in the second form:Private m_Owner As Form

Public Property Get Owner() As Form
Owner = m_Owner
End Property
Public Property Set Owner(value As Form)
Set m_Owner = value
End Property

Private Sub Form_Load()
If Not m_Owner Is Nothing Then
MsgBox "The owner of this form is " & m_Owner.Name
End If
End SubAnd in the first:Private Sub Command1_Click()
Set Form2.Owner = Me
Form2.Show vbModel, Me
End SubIt should say "The owner of this form is Form1" when you load the second form.



Thanks!! Voltface - exactly what I needed.

Rick_Fla
02-12-2004, 01:45 PM
You could create a public property of the second form which allows storage of a Owner manually. For example, in the second form:Private m_Owner As Form

Public Property Get Owner() As Form
Owner = m_Owner
End Property
Public Property Set Owner(value As Form)
Set m_Owner = value
End Property

Private Sub Form_Load()
If Not m_Owner Is Nothing Then
MsgBox "The owner of this form is " & m_Owner.Name
End If
End SubAnd in the first:Private Sub Command1_Click()
Set Form2.Owner = Me
Form2.Show vbModel, Me
End SubIt should say "The owner of this form is Form1" when you load the second form.


I have tried this code and when I compile I get a nice little error message stating invaild use of porperty and it highlights Owner in

Public Property Get Owner() As Form
Owner = m_Owner
End Property

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum