Home > front end >  How do I call a function for 3 buttons all at once in VBA
How do I call a function for 3 buttons all at once in VBA

Time:08-17

I am not familiar with VBA. How do I call a function that calls 3 buttons all at once. The three buttons are already working but how do I call them to all work at once. I have done the below:

Private Sub Command4_Click()
   Call Command1_Click()
   Call Command2_Click()
   Call Command3_Click()
End Sub

CodePudding user response:

You can take de code on each CommandButton_Click and past in to a Sub, so when you clic button1 calls Sub What_Button1_does, and in MasterButton you call all Subs

Private Sub MasterButton_Click()
    What_Button1_does
    What_Button2_does
    What_Button3_does
End Sub

Private Sub CommandButton1_Click()

    What_Button1_does

End Sub

Sub What_Button1_does

    (code from CommandButton1_Clic)

End sub

CodePudding user response:

Like the comments said that should work but, if you are looking for a simulated event. This is what it should look like I think.

Private Sub MasterButton_Click()
    CommandButton1.Value = True
    CommandButton2.Value = True
    CommandButton3.Value = True
End Sub

Though, I would suggest that you make some new methods and have each button call those methods. Then have the master button use all those methods/subs.

As Albert pointed out this doesn't work in Access? It works in excel and word. So ya the only way is to call the click method itself as well as using Call MasterButton_Click()

  • Related