Press a button with another button

Smee

Registered User.
Local time
Today, 23:08
Joined
Dec 16, 2003
Messages
69
Strange problem - but I'm sure it's possible

I want to click a button, and doing so, cause the OnClick event on another button to run.

The reason for this is eventually I want to be able to click one button that effectively runs the code for a dozen buttons.

Thanks in advance
 
Let's assume you have two command buttons, cmd1 and cmd2. By clicking cmd2 you want to run the code that would run if you had clicked cmd1.
Code:
Sub cmd2_Click()
    cmd1_Click
End Sub

You might want to take this a step further and point both cmd1_Click and cmd2_Click to a separate sub like this:
Code:
Sub cmd1_Click()
    MyCode
End Sub

Sub cmd2_Click()
    MyCode
End Sub

Sub MyCode()
    'here's the code that both subs will run
End Sub

Even better: if you create the separate MyCode sub, you can change it into a function like this:
Code:
Function MyCode()
    'here's the code that both subs will run
End Function
Then you can call it by placing =MyCode() into the property sheet instead of [Event Procedure]. That way, you eliminate having listings for 3 separate subs in your code. You just have one function.
 
That will be useful for something else - thanks

However not quite what I need in this case.

cmd1_click imports the data from no.1 spreadsheet for no.1 member of staff
cmd2_click imports the data from no.2 spreadsheet for no.2 member of staff

etc. etc.

I want cmdAll_click to 'click' each of these buttons one by one. It's a request from my boss who doesn't want to have to press them all individually when he wants them all.

Any ideas?
 
Code:
Sub cmd2_Click()
    cmd1_Click
End Sub

Oh - does this do what I want ?!

I'll try it out.

If it does, then thanks. :D
 

Users who are viewing this thread

Back
Top Bottom