Calling a command button on a differnet form...

B

Brad Pears

What is the syntax for calling the command button "click" event for a
command button located on a different form (that is visible)

I tried forms![otherformname].cmdButton_click - doesn't work... I've tried
forms![otherformname].cmdbutton.click - still doesn't work...

I bet the answer is going to make me feel really dumb!

Thanks,

Brad
 
L

LTofsrud

Hi Brad,

While I think that the syntax is probably "cmdButton.OnClick" for the event,
I am not sure if that would work on not.

I find that in these cases where you have code that is required in two
areas, it is better to write the OnClick code as a separate function and then
point the two click events to the one function. The code can either reside
in one of the forms, or better yet, its own module.

For example:

public function Calculate() as Integer
Calculate = 1 + 1
end function

Then any button click event that needs to perform the task can call the
public function in their appropriate click event.

At the end of the day, your code will be much easier to read (and easier for
you to maintain). Hope that helps a bit.

Lance
 
R

RuralGuy

Brad Pears said:
What is the syntax for calling the command button "click" event for a
command button located on a different form (that is visible)

I tried forms![otherformname].cmdButton_click - doesn't work... I've
tried forms![otherformname].cmdbutton.click - still doesn't work...

I bet the answer is going to make me feel really dumb!

Thanks,

Brad

Brad,

I think your code will work if you change the "cmdButton_click" to a
Public
Sub from a Private one.

HTH

RuralGuy
 

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