By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,903 Members | 1,973 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,903 IT Pros & Developers. It's quick & easy.

"Parent" or "Owning" Form of a "Sub-Form"

P: n/a
How does a "sub-form", i.e. one invoked by another form, determine anything
about the form which brought it into existence, i.e., I suppose,
instantiated it? I wanted to so something like this ...

MsgBox("called by " & Owner.Name)

.... but that throws a null reference exception. Parent.Name and
ParentForm.Name also throw null reference exceptions. Form1.Name works -
but that's not very flexible.

My MsgBox, above, is in the constructor of the "sub-form".

Thanks, Bob
Sep 18 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Sep 18, 2:15*pm, "eBob.com" <eBob....@totallybogus.comwrote:
How does a "sub-form", i.e. one invoked by another form, determine anything
about the form which brought it into existence, i.e., I suppose,
instantiated it? *I wanted to so something like this ...

MsgBox("called by " & Owner.Name)

... but that throws a null reference exception. *Parent.Name and
ParentForm.Name also throw null reference exceptions. *Form1.Name works-
but that's not very flexible.

My MsgBox, above, is in the constructor of the "sub-form".

Thanks, *Bob
If you want to show the message box from the constructor, you're most
likely going to need to pass in a reference to the creating from as a
parameter.

I wonder however if you mean you want to know what form showed the
"sub-form". In which case the message box should live in the "Show"
and "ShowDialog" method, but be warned it might only work if you use
the overloaded call that passes in the owning form.

Thanks,

Seth Rowe [MVP]
http://sethrowe.blogspot.com/
Sep 18 '08 #2

P: n/a
If it is an MdiChild, the it can call MdiParent.Name. If as you suggest you
are just doing a ShowDialog type of call, then you could use a StackTrace
object.

"eBob.com" <eB******@totallybogus.comwrote in message
news:uB**************@TK2MSFTNGP05.phx.gbl...
How does a "sub-form", i.e. one invoked by another form, determine
anything about the form which brought it into existence, i.e., I suppose,
instantiated it? I wanted to so something like this ...

MsgBox("called by " & Owner.Name)

... but that throws a null reference exception. Parent.Name and
ParentForm.Name also throw null reference exceptions. Form1.Name works -
but that's not very flexible.

My MsgBox, above, is in the constructor of the "sub-form".

Thanks, Bob
Sep 18 '08 #3

P: n/a
>"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:95**********************************@m45g200 0hsb.googlegroups.com...
On Sep 18, 2:15 pm, "eBob.com" <eBob....@totallybogus.comwrote:
>How does a "sub-form", i.e. one invoked by another form, determine
anything
about the form which brought it into existence, i.e., I suppose,
instantiated it? I wanted to so something like this ...

MsgBox("called by " & Owner.Name)

... but that throws a null reference exception. Parent.Name and
ParentForm.Name also throw null reference exceptions. Form1.Name works -
but that's not very flexible.

My MsgBox, above, is in the constructor of the "sub-form".

Thanks, Bob

If you want to show the message box from the constructor, you're most
likely going to need to pass in a reference to the creating from as a
parameter.

I wonder however if you mean you want to know what form showed the
"sub-form". In which case the message box should live in the "Show"
and "ShowDialog" method, but be warned it might only work if you use
the overloaded call that passes in the owning form.

Thanks,

Seth Rowe [MVP]
http://sethrowe.blogspot.com/
Hi Seth,

What I am after is the name of the form which did the

Dim sform as new SomeForm

i.e. in SomeForm code I want to get the name of who New'ed me. Maybe the
same code will Show me maybe it won't. Maybe it already has maybe it never
will.

Although I ran into the problem in constructor code it seems to me that it
is a general problem. MsgBox has nothing to do with the problem, I was just
using it to experiment and to illustrate the problem. In general I would
say that it is a bad programming practice to try to get at any information
about your creator (unless it is explicitly passed). But I think that there
might be exceptions such as Location (which is what I was after).

What really makes me curious is what Parent, ParentForm, and Owner mean
since not a one of them means what I would have guessed.

Thanks, Bob
Sep 19 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.