PDA

View Full Version : [SOLVED] Call a Macro with 40 different CommandButtons



TheGreatest
01-09-2005, 01:08 PM
Hi,

I have a UserForm with 40 CommandButtons and I have the following macro to call another UserForm with that CommandButtons.


Sub Show_checkin()
Load checkin
checkin.Show
End Sub

if I add the following code to each button, everything works fine


Private Sub button1_Click()
Call Show_checkin
End Sub
Private Sub button2_Click()
Call Show_checkin
End Sub
Private Sub button3_Click()
Call Show_checkin
End Sub
Private Sub button4_Click()
Call Show_checkin
End Sub
Private Sub button5_Click()
Call Show_checkin
End Sub
'
'and this goes up to 40th button...

What I want to know is; is there any shorter way to do this action? I mean one code will work for every button.

Thanks in advance

Richie(UK)
01-09-2005, 01:13 PM
Hi TG,

What you need is a Class Module. JW explains how here :
http://www.j-walk.com/ss/excel/tips/tip44.htm

HTH

Jacob Hilderbrand
01-09-2005, 04:09 PM
We have an example in our KB as well.

http://www.vbaexpress.com/kb/getarticle.php?kb_id=85

Ivan F Moala
01-10-2005, 02:37 AM
Why do you have 40 commandbuttons performing the same function ?
Only ask as it maybe easier if you just designed the need for 40 out rather then look for an easier method of call the same procedure?

Aaron Blood
01-10-2005, 12:32 PM
Why do you have 40 commandbuttons performing the same function ?
Only ask as it maybe easier if you just designed the need for 40 out rather then look for an easier method of call the same procedure?Perhaps the macro performs a different op depending on the button caller?
Only reason I could think of... But even so, I'd probably opt for a listbox then.