Manipulate 'parent' forms 
Author Message
 Manipulate 'parent' forms

I have an app that shows a list of items in a grid. A procedure then create an instance of a form to show details of that item. the item number is
passed via the .tag property:

   Dim MADetail1 As New MAInfo
   MADetail1.Tag = ItemNumber
   Load MADetail1
   MADetail1.Show

That can happen again

   Dim MADetail2 As New MAInfo
   MADetail2.Tag = ItemNumber
   Load MADetail2
   MADetail2.Show

That form again can create a new instance of another form to display a list of information on that item, and most important, manipulate a data control
on the calling form. How can I pass information to the subform  that allows me to do something like

   MADetailx.Data1.Refresh
   MADetailx.Grid1.ReBind
   MADetailx.SetFocus

and pass control back to MADetailx after unloading? I could pass the name of the calling Form via .Tag, but what sort of var do I have to Dim in the
subsubform to use it for manipulating the 'parent'

Dim ParentName as ??????
(Set) ParentName = Me.Tag
ParentName.Data1.Event

Any sort of help or hints where to look greatly appreciated!

Christoph Niessen



Tue, 01 May 2001 03:00:00 GMT  
 Manipulate 'parent' forms
Hello Christoph,

The data type of the parent form is "form".  You can also make a reference
to it by using the forms collection, like so:

Dim frmParent as Form

Set frmParent = Forms(Me.Tag)

' do stuff with the parent form

' release the reference to the parent
Set frmParent = Nothing

I hope this helps,

Larry Tubbs Jr. MCP, MCSD
Silverleaf Resorts Inc., NYSE: SVR

http://home.sprintmail.com/~ltubbs/

Quote:

>I have an app that shows a list of items in a grid. A procedure then create

an instance of a form to show details of that item. the item number is
Quote:
>passed via the .tag property:

>   Dim MADetail1 As New MAInfo
>   MADetail1.Tag = ItemNumber
>   Load MADetail1
>   MADetail1.Show

>That can happen again

>   Dim MADetail2 As New MAInfo
>   MADetail2.Tag = ItemNumber
>   Load MADetail2
>   MADetail2.Show

>That form again can create a new instance of another form to display a list

of information on that item, and most important, manipulate a data control
Quote:
>on the calling form. How can I pass information to the subform  that allows

me to do something like
Quote:

>   MADetailx.Data1.Refresh
>   MADetailx.Grid1.ReBind
>   MADetailx.SetFocus

>and pass control back to MADetailx after unloading? I could pass the name

of the calling Form via .Tag, but what sort of var do I have to Dim in the
Quote:
>subsubform to use it for manipulating the 'parent'

>Dim ParentName as ??????
>(Set) ParentName = Me.Tag
>ParentName.Data1.Event

>Any sort of help or hints where to look greatly appreciated!

>Christoph Niessen



Tue, 01 May 2001 03:00:00 GMT  
 Manipulate 'parent' forms
Assuming you are using VB4 or later, you can create a public Sub in the
detail form, and pass the "parent" form object to it as a parameter. You can
also pass the ItemNumber as a parameter instead of using the Tag property.

Example:

' in form MAInfo
Public Sub ShowDetail (frmParent As Form, ByVal ItemNumber as Integer)
    ' store parameters as module level variables
    Set mfrmParent = frmParent
    mItemNumber = ItemNumber
    ' show this form
    Show
    ' whatever else need doing
End Sub

To communicate back to the parent, just do

    mfrmParent.Data1.Event

Oh yes, and instead of Load'ing and Show'ing the child, call it's ShowDetail
method:

   Dim MADetail1 As New MAInfo
   MADetail1.ShowDetail Me, ItemNumber

-Andy.

Quote:

>I have an app that shows a list of items in a grid. A procedure then create

an instance of a form to show details of that item. the item number is
Quote:
>passed via the .tag property:

>   Dim MADetail1 As New MAInfo
>   MADetail1.Tag = ItemNumber
>   Load MADetail1
>   MADetail1.Show

>That can happen again

>   Dim MADetail2 As New MAInfo
>   MADetail2.Tag = ItemNumber
>   Load MADetail2
>   MADetail2.Show

>That form again can create a new instance of another form to display a list

of information on that item, and most important, manipulate a data control
Quote:
>on the calling form. How can I pass information to the subform  that allows

me to do something like
Quote:

>   MADetailx.Data1.Refresh
>   MADetailx.Grid1.ReBind
>   MADetailx.SetFocus

>and pass control back to MADetailx after unloading? I could pass the name

of the calling Form via .Tag, but what sort of var do I have to Dim in the
Quote:
>subsubform to use it for manipulating the 'parent'

>Dim ParentName as ??????
>(Set) ParentName = Me.Tag
>ParentName.Data1.Event

>Any sort of help or hints where to look greatly appreciated!

>Christoph Niessen



Tue, 01 May 2001 03:00:00 GMT  
 Manipulate 'parent' forms
Thanks for the tip, Larry, but forms(index) needs a numeric value so I can't use the name of the parent instance I create. I'm trying now to pass the
parent's hDC to the child and then find out the parent's form(index) by stepping through all active forms to find out wich one has the appropriate
hDC. But I don't know, what happens if one or more of the open forms are unloaded and the rest is eventually renumbered by VB? But I've made a
considerable step forward.

Thanks again!

Christoph

Larry Tubbs schrieb:

Quote:
> Hello Christoph,

> The data type of the parent form is "form".  You can also make a reference
> to it by using the forms collection, like so:

> Dim frmParent as Form

> Set frmParent = Forms(Me.Tag)

> ' do stuff with the parent form

> ' release the reference to the parent
> Set frmParent = Nothing

> I hope this helps,

> Larry Tubbs Jr. MCP, MCSD
> Silverleaf Resorts Inc., NYSE: SVR

> http://home.sprintmail.com/~ltubbs/



Fri, 04 May 2001 03:00:00 GMT  
 Manipulate 'parent' forms
Thanks for the tip, Andy, but that leaves me with one question: If I create another instance of MAInfo with another Public Sub ShowDetail, how would
the system deal with that? Would It have to go in a .bas module?

Thanks a lot

Christoph

Andy Cook schrieb:

Quote:
> Assuming you are using VB4 or later, you can create a public Sub in the
> detail form, and pass the "parent" form object to it as a parameter. You can
> also pass the ItemNumber as a parameter instead of using the Tag property.

> Example:

> ' in form MAInfo
> Public Sub ShowDetail (frmParent As Form, ByVal ItemNumber as Integer)
>     ' store parameters as module level variables
>     Set mfrmParent = frmParent
>     mItemNumber = ItemNumber
>     ' show this form
>     Show
>     ' whatever else need doing
> End Sub

> To communicate back to the parent, just do

>     mfrmParent.Data1.Event

> Oh yes, and instead of Load'ing and Show'ing the child, call it's ShowDetail
> method:

>    Dim MADetail1 As New MAInfo
>    MADetail1.ShowDetail Me, ItemNumber

> -Andy.



Fri, 04 May 2001 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. MDI parent forms and 'fixed borderstyle'

2. Form in a Parent Form's Frame - Is it possible

3. referencing a control's 'parent'

4. Manipulating another databases' forms

5. Manipulating a form's menu handle

6. Access Parent Form's Menu

7. Child Form Can't Update Parent...

8. MDI child form is moving down from it's parent

9. Can't get HWnd of real parent form since usercontrol container changes during load

10. App.Path of the Usercontrol's Parent form

11. Help on MDI Parent form's menu

12. VB5: Crystal Reports child-window haven't title in MDI-parent form

 

 
Powered by phpBB® Forum Software