Yes, if the form is open. If you're going to reuse the code, though, I'd store
it in a Module and call it from two different places (the first form's button
Click event for example).
As long as the forms are open, no problem. The trick is to
understand that Public procedures in a form are methods of
the form. The standard syntax for calling a method of an
object is:
object.method
In the case of a form method you would use:
Forms!formA.commandbuttonname_Click
Change the code behind the Click event of your command button from, say,
"Private Sub MyButton_Click()" to "Public Sub MyButton_Click()" then use the
line following to execute the code from, say, a module -
Form_MyForm.MyButton_Click (where "MyForm" is the name of your form)
I believe it is NOT necessary that a form be open to use its code.
You call the sub behind the command button with this line -
Form_frmFormName.cmdButton_Click
where frmFormName is the name of the form containing the command button and
cmdButton is the name of the command button.
BUT FIRST YOU MUST change the clcik procedure behind the command button from
"Private Sub cmdButton_Click()" to "Public Sub cmdButton_Click()".
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.