Nope, not even with XP/2002. Not sure why but it's not possible!
Please rate this post if it was useful for you!
Please try to search before creating a new post,
Please format code using [ code ][ /code ], and
Post sample code, error details & problem details
You may create an array of control objects and share single event procedures. For example, say you have any number of textboxes on some userform:
Code:
'place the following in a userform
Dim AobjTextBoxes() As New Class1
Private Sub UserForm_Initialize()
Dim intCtlCnt As Integer, objControl As Control
For Each objControl In Me.Controls
If TypeOf objControl Is MSForms.TextBox Then
'if you wish to exclude object
'do it here...
intCtlCnt = intCtlCnt + 1
ReDim Preserve AobjTextBoxes(1 To intCtlCnt)
Set AobjTextBoxes(intCtlCnt).TextBoxEvents = objControl
End If
Next objControl
Set objControl = Nothing
End Sub
'place in a Class module
Public WithEvents TextBoxEvents As MSForms.TextBox
Private Sub TextBoxEvents_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
MsgBox "Mouse down"
End Sub
I realize this is an old thread but hopefully someone will read it.
I am trying to creat a control array of command buttons in VBA similiar to the textbox example.
I am able to get the common event click to work but cannot find a way to to creade an index to determine which button was clicked.
In the sample there are three Command Buttons. This works as is but I need an index for the button clicked. I tried adding Index as Integer and ByVal Index as Integer but got the error:
"Procedure declaration does not match description of event or procedure having the same name."
Here is a sample of what I have:
VB Code:
Dim arCommandButton(1 To 3) As New Class1
Private Sub init()
Set arCommandButton(1).ButtonEvents = cmd1
Set arCommandButton(2).ButtonEvents = cmd1
Set arCommandButton(3).ButtonEvents = cmd1
End Sub
'In a Class Module
Public WithEvents ButtonEvents As MSForms.CommandButton
Private Sub ButtonEvents_Click()
MsgBox "Button clicked."
End Sub
Thank you for any help you can give:
Last edited by jsanford; Nov 1st, 2005 at 11:16 AM.
This is an array that I created at run time and thus does not have propertys such as index. I could actually use the name property of the command button but how do I pass it through the withevents and access it in the buttonevents sub? The real question is can I pass this through to the sub????
It appears from the textbox example from an earlier thread that it is possible but since I am not a skilled programer I am not sure if it is really possible.
Hello,
I've done that, but i want something other.
I want to have a commands array, and labels array with zeros caption.
when I click on a command, the label with the same index will increase.
I pray that the idea is obvious...