broadbent
asked on
Using control created at runtime
I have a form in VBA which has a command button. Every time I click it I create a new command button.
How do I attach an event to the new buttons, so that when I click any of themm, I can run some code?
The code so far is as follows:-
Dim Mycmd As Control
Private Sub CommandButton1_Click()
Static i&
i& = i& + 1
Set Mycmd = Controls.Add("Forms.Comman dButton.1" )
With Mycmd
.Left = 12
.Top = 25 * i& + 25
.Caption = .Name
End With
End Sub
How do I attach an event to the new buttons, so that when I click any of themm, I can run some code?
The code so far is as follows:-
Dim Mycmd As Control
Private Sub CommandButton1_Click()
Static i&
i& = i& + 1
Set Mycmd = Controls.Add("Forms.Comman
With Mycmd
.Left = 12
.Top = 25 * i& + 25
.Caption = .Name
End With
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
sorry , but controls in VBA can't be indexed!
Thats the problem
Thats the problem
if i was in a situation that i know nothing about it - i would not understand a thing from his answer.
traygreen, if u AnswerTheMan - do it from your heart.