Running a function on another form

sjn78

Well-known member
Joined
May 4, 2003
Messages
255
Location
Australia
This has got me puzzled.

I have a combobox on the a parent form which has mdi children. The combo is used sort of like a filter. EG, 2000, 2001. The idea of it is to limit the records to only show the ones in the year selected.

When I change the year, I want all of the mdi children that are open to call a predetermined function on their own form to run through and select records for that year only.

I can run through each open window ok, but when it comes to calling the function, it tells me there is no object.

This is what I have so far. This function is on the main form where the combobox is.

Function SeasonPick(ByVal sea As String)

Dim win As Form

showseason = sea

For Each win In Me.MdiChildren
If win.Name = "FrmManageContacts" Then
win.Focus()

I want to be able to do the following.....its not right though.

win.TreePopulate(showseason)

End If
Next

The TreePopulate is the function on the FrmManageContacts form. I have made this function Public.


If anyone could help out, it would be great.

Steve
 
Fiorst of all, you cannt access a function of a form from anywhere outside the form. So do like ailzaj suggested. Wrap that function in a Module or Class.
Did I get it right, that you want to get the year from a combobox on the MDI-Parent?
 
Cast your win variable to the form you need.
Something like this:
Code:
Dim win as Form
For Each win in Me.Controls
        if win.Name = SomeName1 then
              DirectCast(win, SomeName1).TreePopulate(showseason)
        elseif win.Name = SomeName2 then
               DirectCast(win, SomeName2).SomeMethod
        End If
next

This will allow you to acces form class specific methods and things like that.
 
Last edited by a moderator:
Originally posted by APaule
Fiorst of all, you cannt access a function of a form from anywhere outside the form.

This is incorrect. If the function or method (or variable, constant
or anything else) is declared as Public, it can be accesed through
any instance of the form.
 
I got it to work as per Mutants suggestion. Thanks Mutant.

I dont know what I would do without these forums!!!

Steve
 
Back
Top