Accessing public sub in startup form

  • Thread starter Thread starter Steve Enzer
  • Start date Start date
S

Steve Enzer

My project uses a MDI parent form and several child forms. I need to call a
public sub in the parent form (which is also the startup object) from one of
the child forms in order to change the appearance of the toolbar under
certain conditions. So far I have not figured out how to reference the sub
from another form. I figure I need the object name of the startup form, but
since I don't declare this in code as I do the other forms, I haven't been
able to find what this is. Using the class name ("frmMain") doesn't work.

Thanks for any advice.
Steve Enzer
 
when instantiating child in main
frmChild.owner = me

when needing to call sub from child
ctype(me.owner, frmMain).subToExecute
 
Thanks for your advice, but I'm getting an error with the code you
suggested.

I'm using the statement:
CType(Me.Owner, frmMain).TestBox()

to call the public subroutine TestBox in frmMain. When I test the code I
get an exception with the message:

"An unhandled exception of type 'System.NullReferenceException' occurred in
Project Manager.exe

Additional information: Object reference not set to an instance of an
object."

What do I try next? I'm a VB6 programmer trying to start a new project in
VB .NET 2003 and I'm still on the steep part of the learning curve.
 
Steve,

Use mdiParent instead of Owner in Champs advice or even very slightly
better.

DirectCast(me.MdiParent,frmMain).mysub

I hope this helps,

Cor
 
Your 'Owner' property is not set to a value. To use this techique, you'd
need to set the Owner property after creating the child form. Can you post
the code that does that?

(btw: Cor's technique is better, IMHO)

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
 
Back
Top