Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.


Is there a way to click a button on one from from another form?

Is there a way to click a button on one from from another form?

I have a form in my database named 'OrderMenu_frm' that allows a user to match items from a sales order.

The data from the sales order is populated onto the OrderMenu_frm if the user clicks a "Get New Order" button
on this form.

The user then matches sales order items on this form that are to be configured into a record and clicks a "Match Selected"
button on this form which places the matched items as a record in a table called Total_Items_tbl.

When a match is performed the items that were matched are removed from the form to avoid duplicate items being matched.

Once the user is finished matching all items from the sales order they click a Verify Matched Items button on this form
which opens a continuous form called "SalesOrder_frm" which displays the contents of the Total_Items_tbl table.

From this "SalesOrder_frm" continuous form, the user can edit any of the records displayed. Once finished the
user can click one of two buttons (Add to Database or Discard).

Sorry for the long description and here is the question:

For the Discard button, I want to close this "SalesOrder_frm" continuous form but with the 'OrderMenu_frm' still
open is there a way to automatically run the "Get New Order" button code on the 'OrderMenu_frm' so it populates the
order data back onto this form?

I was reading about setting the Control Source property of a control as =[SalesOrder_frm].Form![Discard_btn] but the Control Source property
does not appear to be available for a button control where I would attempt to apply this to the "Get New Order" button

I appreciate suggestions on how to do this...


RE: Is there a way to click a button on one from from another form?

I would create a simple form with a command button that pops up a msgbox(). Then create another form with a command button that you want to call the command button code from first. You can then add code to the new form command button with something like:

CODE --> vba


You might have more time and interest in doing this than me at the moment.

Hook'D on Access
MS Access MVP 2001-2016

RE: Is there a way to click a button on one from from another form?

Thanks Duane-

That method would add a couple additional messages boxes and I am wondering if might it be cleaner for the user if I was to add the same code under my Discard button as I
have under my Get New Order button on the first form and then do a requery of the first form before closing the form with the Discard button.

Can a requery command be sent to another form?

RE: Is there a way to click a button on one from from another form?

Why not move the code outside the forms with the required arguments if any from the forms? This makes the code stand on its own and not depend on any form.

Hook'D on Access
MS Access MVP 2001-2016

RE: Is there a way to click a button on one from from another form?

You can requery another open form by;

RE: Is there a way to click a button on one from from another form?


Quote (MajP (TechnicalUser)8 Dec 17 20:15 You can requery another open form by; Forms!YourFormName.requery)

I tried the following but it doesn't seem to have any affect on form OrderMenu_frm:

CODE -->


End Sub 

RE: Is there a way to click a button on one from from another form?

Can you post the complete code so we can see the event from where it is called?
To verify this works I made 2 forms "frm1" and "frm2". Bound to the same data. I open both forms and then make changes in form 1. In frm1 I have this code.

Private Sub Form_Close()
End Sub

When I close frm1 it requeries frm2 and you see then see the changes.

RE: Is there a way to click a button on one from from another form?

Thank you MajP and Duane for your suggestions.

Turns out I messed up as the parts on the form that I wanted to requery were subforms...

so once I remembered that I have to handle them separately I simply put the following into the
close event of the form and all is well:



RE: Is there a way to click a button on one from from another form?

To more directly answer the question...

No you can not run a button on another form. Events on forms are private which means they can't be called.

However, you can call a private event in a module, including a form's class module with a public procedure in the module.

Then it is a matter of calling the procedure... I think a fully qualified form reference and the procedure name is the right syntax since it is a class module and therefore a method of the instance.

As to whether you put the code in the public procedure called by the event or the code in the event called by the public procedure is a style choice to me (mine would be to call the private procedure in the public one so as not to confuse changes by less accomplished programmers in the future and break my code). That said there are compelling arguments for putting some code outside the module altogether for reuse on multiple forms. The opposing argument would be that by putting all the code on the form, you maintain object portability and if you copy it to another system it is more likely to work.

RE: Is there a way to click a button on one from from another form?

Sorry to be picky, but there is some wrong terminology here and not exactly true. There is a big difference between an Event and an Event Handler (Event Procedure). The event procedure is the thing that listens for and handles the event. You cannot make a button physically click (raise the click event) from an external module, but you can call the code in its event procedure. Event Procedures are only private by default when using the VBE, but there is no reason you cannot make them public and call them from outside the form.
The below event procedure can be called from outside the form module using the syntax

CODE -->

Public Sub Command5_Click()
     MsgBox "Hello World"
End Sub 
Events are not called they are Raised. Event Handlers (Event Procedures) handle a raised event. You can make your own event and Raise it. Here is an example. In Form2 I create an event called a HelloWorld event. I raise that event after a message box pops up.

CODE -->

Public Event HelloWorld()
Public Sub Command5_Click()
  MsgBox "Hello World"
  RaiseEvent HelloWorld
End Sub 
Now in Form1 I can write the event procedure to handle the HelloWorld event

CODE -->

Public WithEvents frm2 As Form_Form2
Private Sub Form_Load()
  Set frm2 = Forms!Form2
End Sub
Private Sub frm2_HelloWorld()
  MsgBox "Form 2 Said Hello World"
End Sub 
Now in form2 when the Command5_Click procedure executes it raises an event. Form1 handles that event and will pop up a message box. However, there is no way to Raise this event external to Form2. Probably more useful than making custom events is handling other Form events. So Form1 can do something when you do something of Form2.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close