Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do i add an event to a control created at runtime? 1

Status
Not open for further replies.

Transcend

Programmer
Sep 29, 2002
858
AU
Hi guys

if i create a control at runtime, like so

Set optButtons = Controls.Add"VB.OptionButton",name)

is it possible to write code to capture events, like click events?

Transcend
[gorgeous]
 
Try this:

Private WithEvents Command2 As CommandButton
Private Sub Command1_Click()
Set Command2 = Form1.Controls.Add("VB.CommandButton", "Command2")
Command2.Visible = True
Command2.Caption = "Click Me"
Command2.Top = 100
Command2.Left = 100
End Sub
Private Sub Command2_Click()
MsgBox "I've been clicked"
End Sub

"Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top