capture events in dynamic form controls

G

Gary Mc

I am trying to create runtime text fields and then capture events on this
text field. I have experimented with several things I have found on the
internet, but have been unsuccessful. The form shows when I run it and the
text box appears, but when I click in it, I do not invoke the control event.
Any ideas?

I have a class module: MyCtrlEvents

******
Option Explicit
Public WithEvents MyBox As MSForms.TextBox

Private Sub MyBox_Click()
MsgBox MyBox.Name & " click!"
End Sub
******

And I have a form with nothing on it. Here is the code.

******
Dim c() As MyCtrlEvents


Private Sub UserForm_Activate()


ReDim c(1)
Set c(0) = New MyCtrlEvents

Set c(0).MyBox = Me.Controls.Add("Forms.Textbox.1")
With c(0).MyBox
.Name = "TextBoxTest"
.Top = 42
.Width = 72
.Height = 18
.Left = 20
End With

End Sub
*****
 
D

Dick Kusleika

Gary

The MSForms.TextBox control doesn't have a click event. Use the dropdown
boxes at the top of the code pane to see what events are available.
 
G

Gary Mc

Thanks Dick. I feel like a idiot! I had been using the dbl-click event and
had changed it to a click even for some reason. Works great now. Thanks for
your help!

Gary
 

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