PC Review


Reply
Thread Tools Rate Thread

Add Controls to Control Collection at Run Time

 
 
ExcelMonkey
Guest
Posts: n/a
 
      5th Aug 2008
I have a for that I want to add various controls to. I want to dilineate the
controls by adding them to two separate collections. Once added, I will have
two separate buttons which I will click. One button's click event will show
the controls in the first collection and the second button's click event will
show the controls in the second collection. I am getting error 424 in my
button click events in my For..Next stmts. What am I doing wrong?

'****************************************
Public CntrlColctn1 As Collection
Public CntrlColctn2 As Collection

Public lbl As Label
Public cmbx As ComboBox
Public btn As Button

Public chkbx As CheckBox
Public lstbx As ListBox
Public frm As Frame

'**********************************
'Regular Module
Public Sub Thing()
UserForm1.Show
End Sub
'**********************************
Private Sub UserForm_Load()
Set lbl = Me.Add(Label)
Set cmbx = Me.Add(ComboBox)
Set btn = Me.Add(Button)

Set chkbx = Me.Add(CheckBox)
Set lstbx = Me.Add(ListBox)
Set frm = Me.Add(Frame)

CntrlColctn1.Add (lbl)
CntrlColctn1.Add (cmbx)
CntrlColctn1.Add (btn)

CntrlColctn2.Add (chkbx)
CntrlColctn2.Add (lstbx)
CntrlColctn2.Add (frm)
End Sub
'************************************
Private Sub CommandButton1_Click()
Dim x As Control
For Each x In CntrlColctn2
x.Hide
Next
For Each x In CntrlColctn1
x.Show
Next
End Sub
'********************************
Private Sub CommandButton2_Click()
Dim x As Control
For Each x In CntrlColctn1
x.Hide
Next
For Each x In CntrlColctn2
x.Show
Next
End Sub

Thanks

EM
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Run time error 91 when trying to add controls to a collection ExcelMonkey Microsoft Excel Programming 3 6th Aug 2008 10:57 PM
this.Controls.Add(Control) Does Not Add Control to child collection (this.Controls.Count == 0) Chad Scharf Microsoft ASP .NET 3 18th Oct 2007 04:53 PM
Get Reference to a Specific Control in the Controls Collection Jeffrey Todd Microsoft C# .NET 1 2nd Jun 2005 02:09 AM
Make a control Readonly using the controls Collection =?Utf-8?B?R1A=?= Microsoft ASP .NET 10 19th Nov 2004 09:22 PM
Dynamic Composite Controls And Their Child Control Collection Harry Microsoft ASP .NET 2 16th Apr 2004 08:15 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:39 PM.