Call onclick procedures in another form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

From the command button (Command1) on the current form, I want to open
another form (form2) and call the On-click event of another button (Command2)
on form2. I tried the following method but they are not working. Is this
possible? Has anyone tried this?

Here's what I tried but unsuccessful:

Call cmdCompanyAdd_Click
' or
[Forms]![COMPANY RETURN ADDRESS ADD CHANGE]![cmdCompanyAdd].Click

Any help is very much appreciated. Thanks.
 
By default, event procedures are private, e.g. ...

Private Sub Command2_Click()

This means that they are available only to code in the same module. In order
to make the code available to code in other modules, you must change the
'Private' keyword to 'Public' ...

Public Sub Command2_Click()

You can then call the procedure from another module like so ...

Forms("Form1").Command2_Click

The form ("Form1" in this example) must be open when you call the procedure.

It is usually preferable, however, to put code that will be used by more
than one form in a standard module.
 
Works like a charm! and learn something new today. Thank you so much Brendan!

Brendan Reynolds said:
By default, event procedures are private, e.g. ...

Private Sub Command2_Click()

This means that they are available only to code in the same module. In order
to make the code available to code in other modules, you must change the
'Private' keyword to 'Public' ...

Public Sub Command2_Click()

You can then call the procedure from another module like so ...

Forms("Form1").Command2_Click

The form ("Form1" in this example) must be open when you call the procedure.

It is usually preferable, however, to put code that will be used by more
than one form in a standard module.


--
Brendan Reynolds


Samantha said:
From the command button (Command1) on the current form, I want to open
another form (form2) and call the On-click event of another button
(Command2)
on form2. I tried the following method but they are not working. Is this
possible? Has anyone tried this?

Here's what I tried but unsuccessful:

Call cmdCompanyAdd_Click
' or
[Forms]![COMPANY RETURN ADDRESS ADD CHANGE]![cmdCompanyAdd].Click

Any help is very much appreciated. Thanks.
 

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

Back
Top