Calling a command button on a differnet form...

  • Thread starter Thread starter Brad Pears
  • Start date Start date
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
 
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
 
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
 
Back
Top