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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create a global object accessed from MDI parent form

Status
Not open for further replies.

sony2000

Programmer
Dec 7, 2003
34
0
0
HK
Hi,

My program has a MDI form and a child form. I create a ImageList and set it as a public attribute. But in my
child form, when I type :

Dim frm as new frmMDI()

there is no the imagelist available in the property lists
when I type "frm.", does any one know what is wrong with
my concept or coding?

Thanks for your kind attention,
Raymond
 
Hi ThatRickGuy,

I declared a public variable db_conn which is a database
connection object in MDI parent form.

I tried me.parentform to access the public properties and
functions from MDI parent form. But there is no
db_conn can be selected......please help me.

Thanks,
Raymond

 
Code:
  Private Sub DoSomethingOnParent(ByVal strName As String)
    Dim ctlIterater As Control
    'cycle through all of the controls in the controls collection on the parent form
    For Each ctlIterater In Me.ParentForm.Controls
      If ctlIterater.Name = strName Then
        'do something
      End If
    Next
  End Sub

Untested, but that code will loop through all of the controls on the parent form looking for the one that you specify the name of.

----------------------
 
I think you will need something like

dim Pform as parentformname
pform = me.parentform
pform.db_conn.open

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Is there any "global" way to access the public variable in
MDI form? why those public variable do not appear in
the function/property list?

Raymond
 
Has something to do with OOP and all that difficult stuff.

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Another great function that can help is the CallByName method. In an app that I was working on yestarday I had a user control that I wanted to update the parent form's status bar from, but since the .parentform returns a form object at design time, I couldn't compile it using me.parentform.sbrMessage. But what I could do was this:

Code:
Dim sbrMessages As StatusBar 
  sbrMessages = CallByName(Me.ParentForm, "sbrMessages", CallType.Get)
  sbrMessages.Panels(0).Text = strText

-Rick

----------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top