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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating Controls @ Run-time

Status
Not open for further replies.

Debeast

Programmer
Jul 18, 2002
28
GB
Hi ppl

Am i right in thinking if you create a control using :

form1.controls.add "vb.listbox", "LSTNAT"

you WILL NOT be able to use the events for that control?

but if i use :

Load LSTNAT

i WILL be able to use the events?

Nathan
 
consider the following.

Code:
Option Explicit

Private WithEvents cmdCreated As CommandButton

Private Sub Command1_Click()
  Set cmdCreated = Form1.Controls.Add("VB.CommandButton", "cmdCreated")
  
  cmdCreated.Top = 0
  cmdCreated.Left = 0
  cmdCreated.Caption = "Created"
  cmdCreated.Visible = True
End Sub

Private Sub cmdCreated_Click()
  MsgBox "cmdCreated event"
End Sub

there was a thread a few days ago about dynamically creating controls but I cannot find it.
 
Thanks mate

the code is perfect :)

You're a scholor and a gentleman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top