954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

adding objects at runtime

How can i add objects such as buttons, labels or textboxes at runtime?

K-Dave
Newbie Poster
18 posts since Jan 2008
Reputation Points: 10
Solved Threads: 1
 

Hi
Example to adding control at runtime

Option Explicit
' Declare object variable as CommandButton.
Private WithEvents cmdObject As CommandButton 

Private Sub Form_Load()
   Set cmdObject = Form1.Controls.Add("VB.CommandButton", "cmdOne")
   cmdObject.Visible = True
   cmdObject.Caption = "Dynamic CommandButton"
End Sub

Private Sub cmdObject_Click()
    MsgBox "This is a dynamically added control"
End Sub
selvaganapathy
Posting Pro
547 posts since Feb 2008
Reputation Points: 44
Solved Threads: 100
 

Yes u can, i think selvaganapathy was given the best answer :)

Jx_Man
Nearly a Senior Poster
3,329 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You