Originally Posted by
Paul_Hossler
...I don't want to show a message, but I'm stuck on how to return which button was Clicked back to the calling program. A Public variable just seems 'not right'
Originally Posted by
Paul_Hossler
...BUT .... I thought I could just use a Property Get to return which command button was clicked, and so far I haven't figure out how
Hi Paul,
I might still be misreading what you are asking, but are you wanting to avoid a Public variable in a Standard Module (to hold the value returned by the button) and would rather store the value in the Form?
Maybe like:
UserForm code:
Option Explicit
Private cButtons(1 To 42) As clsButton
Private lButtonVal As Long
Public Property Let ButtonValue(bv As Long)
lButtonVal = bv
End Property
Public Property Get ButtonValue() As Long
ButtonValue = lButtonVal
End Property
Private Sub CommandButton1_Click()
If Me.ButtonValue > 0 Then
Me.TextBox1.Value = ButtonValue
Else
Me.TextBox1.Value = "No button pushed"
End If
End Sub
Private Sub UserForm_Initialize()
Dim ctl As MSForms.Control
Dim n As Long
n = 0
For Each ctl In Me.Controls
If ctl.Name Like "cmdDAY_##" Then
n = n + 1
Set cButtons(n) = New clsButton
Set cButtons(n).ParentForm = Me
Set cButtons(n).ThisCommandButton = ctl
cButtons(n).ButtonValue = n
End If
Next
End Sub
Class:
Option Explicit
Public WithEvents ThisCommandButton As MSForms.CommandButton
Private objPF As Object
Private lButtonVal As Long
Public Property Set ParentForm(pf As Object)
Set objPF = pf
End Property
Public Property Get ParentForm() As Object
Set ParentForm = objPF
End Property
Public Property Let ButtonValue(bv As Long)
lButtonVal = bv
End Property
Public Property Get ButtonValue() As Long
ButtonValue = lButtonVal
End Property
Private Sub ThisCommandButton_Click()
ParentForm.ButtonValue = Me.ButtonValue
End Sub
Is that anything like what you were wanting?
Mark