Call Function

A

Abe Katz

Hello All,
I have an event function on a Command button on a main form.
I want to call the procedure from the sub form, but it doesn't work.
i.e. Call Command_Button_Click().
I even changed it to a Public function.
Thanks in advance
 
D

Dirk Goldgar

Abe Katz said:
Hello All,
I have an event function on a Command button on a main form.
I want to call the procedure from the sub form, but it doesn't work.
i.e. Call Command_Button_Click().
I even changed it to a Public function.
Thanks in advance


If the procedure is on the main form, and you want to call it from a
subform, you need to prefix the call with a reference to the parent form,
like this:

Call Me.Parent.Command_Button_Click

That should work, provided that the procedure has been made Public.
 
M

MikeB

Dirk Goldgar said:
If the procedure is on the main form, and you want to call it from a
subform, you need to prefix the call with a reference to the parent form,
like this:

Call Me.Parent.Command_Button_Click

That should work, provided that the procedure has been made Public.

Why would it have to be Public if you are walking the object tree?
 
D

Douglas J. Steele

MikeB said:
Why would it have to be Public if you are walking the object tree?

By default, events are Private. That means that they can only be called from
within the class module in which they're defined. Since you're trying to
call from a different module (i.e.: the class module associated with the
subform), it won't work unless it's public.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top