Clicking multiple Command button in Single click

vivekt

New member
Local time
Today, 12:35
Joined
Jun 26, 2019
Messages
1
I have a Form with 4 Command buttons in that 3 command Buttons were used to send email for a specific area based on query with filter.

I am trying to use the 4th Command button which when clicked will click on 3 buttons at once sending 3 emails. Is there any way to achieve it through Access . please help me know?
 
Just Call each button from the 4th Button:

Code:
Private Sub Button4_Click()
  Call Button1_Click
  Call Button2_Click
  Call Button3_Click
End Sub
using your actual button names, of course.

Welcome to Access World!

Linq ;0)>
 
Linq beat me to it.
The Call command can be omitted and it will still work fine
 
It's not considered good practice to directly call the code associated with a control.

The correct way to do it would be to create a function or subroutine for each command button and then call those routines from the relevant command button, then call those routines from the fourth button.

That's a perfectly valid method of doing this.
However, I see nothing wrong with calling existing code. In what way us it bad practice?
 
I didn't say it was bad practice I said it was not considered good practice. There's a subtle difference.

It's one of those things we all do from time to time. However the correct way to structure code that is called from multiple places is to separate your code out into its own function or subroutine.

Of course I agree about creating procedures that are going to be called from multiple places. However, in this case the code is being called from just 2 places - the original button and one other button. The amount of code required is the same by either method.
In fact, two places is not the same as multiple places -there's a subtle difference :rolleyes:
 
Minor point about verbiage.

Can call a subroutine from control's event.

Can't call a subroutine from control's event property.

Functions can be called from macros, queries, properties (ControlSource and events) but not subroutines. So this is where Access forces use of functions.
 
In other words you are not allowed to run a subroutine from a controls event.
Most control events are subs, so I wonder if that's what you really meant to say. I'm going to suggest that this has more to do with what you can assign a procedure to when that procedure is not a built in event, and the assignment has to be a function. No idea why. It's probably common knowledge that only a function can be called from a menu, toolbar or ribbon. Furthermore, only a function can be assigned to a control event where the procedure for that event is not a built in one.

Another option for the original question would be the same function that accepts the control name as an argument and acts accordingly - not necessarily would I do that for this case. There may be a better design approach before we got to this stage; e.g. a combo to make some selection. Anytime I see multiple controls being used for basically the same thing, my design hat starts to twinkle.
 
To add to Uncle's post, the only reason I've been told "Don't do it" is because you want to make sure that each control's code executes properly. If you have a set of functions that return true OR false consistently when they complete properly you can use them from each control as well as from ONE control that verifies each has done its job. This normally comes up when button A does something and button B needs button A's code to have finished correctly. Think "A saves a report to disk". B Emails the report A created. If A fails, you should skip having B execute.
 

Users who are viewing this thread

Back
Top Bottom