Thank you for being a valued part of the CNET community. As of December 1, 2020, the forums are in read-only format. In early 2021, CNET Forums will no longer be available. We are grateful for the participation and advice you have provided to one another over the years.

Thanks,

CNET Support

General discussion

how to call a command button from another form

Aug 18, 2010 9:34PM PDT

I have a formA with command button named command15, I also have another formB with command button called command39.

On click event on command39 i want to call command15, knowing that they are on different form

Pls can any body help

Discussion is locked

- Collapse -
Re: command button
Aug 18, 2010 9:50PM PDT

My guess: you're talking about MS Access. If I'm wrong, please correct me.

What I should do in such a case: write a separate module (either a VBA module or an Access macro) and call that from the click event of both command buttons. The code contained in a form can use local variables defined in the form (which aren't available in the other form), so a direct call from one form to another isn't possible.

Kees

- Collapse -
Change 'Private' to 'Public'
Aug 20, 2010 3:35PM PDT

Declare Command15_Click() in FormA as Public instead of Private.
Then call it from Command39_Click like below:

Call FormA.Command15_Click

Make sure FormA is open when you run that line.

Hope it helps,

Dan