I'd create an Event Handler because I couldn't be bothered adding code to each command button, but if you don't feel comfortable with classes, you might get away with something like:
Private Sub CommandButton1_Click()
BtnClick Me.CommandButton1
End Sub
Sub BtnClick(ByRef btn As MSForms.CommandButton)
If btn.BackColor = 13485434 Then Exit Sub
btn.BackColor = 13485434
CCaption = btn.Caption
ECaption = "Loft Quilt "
Supplier = "Central Purchasing"
GLCode = "5002"
ButtonClick
End Sub
Sub ButtonClick()
MsgBox "sdfsdf"
End Sub
If you're interested, the event handler class would look something like:
Class CbtnHandler:
Public WithEvents btn As MSForms.CommandButton
Private Sub btn_Click()
If btn.BackColor = 13485434 Then Exit Sub
btn.BackColor = 13485434
ButtonClick
End Sub
Private Sub ButtonClick()
MsgBox btn.Caption
End Sub
Form implementation:
Dim btns As Collection
Private Sub UserForm_Initialize()
Dim oBtn As CbtnHandler
Dim ctl As Object
Set btns = New Collection
For Each ctl In Me.Controls
If TypeName(ctl) = "CommandButton" Then
Set oBtn = New CbtnHandler
Set oBtn.btn = ctl
btns.Add oBtn
End If
Next ctl
End Sub
This approach would need no code in the button click subs
Bookmarks