Dynamic Control addition and Event response

K

Ken Soenen

I dynamically added a CommandButton using the ADD method as shown below. Now
the problem is: How do I define?,create?,handle? the click event that is
generated by that control. I have tried putting in event handlers named:

Private Sub CommandButton1_Click()
Private Sub Zbut_Click()
Private Sub ZButton_Click()

and none work.

Thanks,
ken

Dim ZButton As Control
Set ZButton = Controls.Add("Forms.CommandButton.1", "ZBut")
With ZButton
.left = 17
.top = 30
.Width = 12
.Height = 12
.BackColor = &H8000000F
.ForeColor = &H80000012
.Caption = "Z"
.FontSize = 10
.Font.Bold = True
End With
 
K

Ken Soenen

Thanks Dave. I tried Chip's "code creation stuff" but the problem still is
selecting the "NAME" XXXX that would be placed in front of the "_Click()"
in the event handler declaration. Like: Private Sub XXXX_Click().

ken
 
T

Tom Ogilvy

Not sure why you are adding a control with code - I would bet there is a
simpler way to accomplish what you need. Nonetheless, you might look at
John Walkenbach's sample:

http://www.j-walk.com/ss/excel/tips/tip76.htm

--
Regards,
Tom Ogilvy


Ken Soenen said:
Thanks Dave. I tried Chip's "code creation stuff" but the problem still is
selecting the "NAME" XXXX that would be placed in front of the "_Click()"
in the event handler declaration. Like: Private Sub XXXX_Click().

ken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top