Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MDI - how to determine child form that called another child form

Status
Not open for further replies.

CraigBest

Programmer
Aug 1, 2001
545
0
0
US
I am new to MDI programming. I have a situation where I have a child form that an instance of is created when a database record must be displayed. More than one instance of this child form can be instanced at one time.

I also have another child form that is called from the first child form, an edit wizard form. This form is used to edit data displayed in the calling child (display) form, where the data is held also.

I am a little confused as to how I can keep a connection between an edit wizard form and the display form that called it if there is more than one display form open in the project. Can someone give me an idea of how this could be done? I have been through the MSDN disks and have not found a suitable answer.
 
You can declare a Public Form variable in the second child form to reference it's parent form through the Me keyword:

'in the edit wizard child form
Dim mfrmParent as Form


' Then in the first Child form
Dim frm as new frmEditWiz
Set frm.mfrmParent = Me



Mark
 
Mark, thank you.

May I ask a couple of questions, as I am not sure I understand completely.

You say to declare the Form variable as public in the EditWiz form, but you declare it as

Dim mfrmParent as Form

If declared in the General Declarations section of the form, does this not declare the variable as a module-level variable (Private) and not as a public variable? I am confused. Seems to me it should be declared as a public variable since it must be accessible from another form.

In the first child form (Let's call it frmDisplay) When I am ready to use the EditWiz form, I declare a new instance of the form:

Dim frm As New frmEditWiz

(Again, is Dim the proper scope for this?)

And then set the Form variable on the frmEditWiz Instance to the frmDisplay which called it by using the Me keyword.

frm.mfrmParent = Me

Is this enough to keep the EditWiz form from getting confused if there are other Instances of the frmDisplay form running? The Me keyword gives the child form enough information to know which form among many it is related to?

And can I then use mfrmParent as a qualifier if I want to update variables on the frmDisplay form from the frmEditWiz form? Like Thus:

mfrmParent.strClientName = "Foo" (Where strClientName is a variable defined on the frmDisplay form?)

This is especially important to me and could save me a lot of greif. Looking forward to your answer.

Thanks again.
 
hi craig,

I could give u a suggestion that can make u more happy and comfortable.Donot call another form for editing.jus have a frame which contains all the controls for editing.Show the frame when edit is clicked.once edit is over u can make the frame invisible.This way u can avoid connecting called forms to calling forms.

If this doesnot satisfy you u can instantiate your form display into a control array,remember the index of the form when it calls the edit form and transfer back control when edit is over.

best way is :
calledform.tag=callingform.index

reply if this works

Rajendra
sairajendra@hotmail.com
 
You're right. The the edit wizard child form should declare the mfrmParent as Public such as:

Public mfrmParent as Form

Sorry for the confusion, I got ahead of myself.

The Me keyword provides a way to refer to the specific instance of the class where the code is executing. You can use the mfrmParent as the qualifier to update Public variables on the parent form and also to update control values (which are public by nature).

Say, for instance you want to instantiate a Wizard Form to assist in the creation of a string and need to return that string to a parent form textbox. In the wizard form, the Public variable mfrmParent is set using the Me keyword in the calling form to identify to the wizard form (and you could also identify a particular control using the same method) contains the textbox to update.

The Calling and Wizard Forms would reference the updates this way:
Code:
' Calling Form has one command and one textbox
Public mstrVar As String

Private Sub cmdWiz_Click()
    Dim frm As New frmWizard
    Set frm.mfrmParent = Me
    frm.Show
End Sub


' Wizard Form has one command button
Public mfrmParent As Form

Private Sub cmdSave_Click()
    mfrmParent.mstrVar = "hello" ' public variable
    mfrmParent.Text1.Text = mfrmParent.mstrVar & " world"  ' control
End Sub

By designating the calling form in the wizard form you can ensure the proper form gets the string update no matter how many calling forms and wizard forms are open.


Mark



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top