PC Review


Reply
Thread Tools Rate Thread

424 Error whem trying to change Visible property

 
 
ExcelMonkey
Guest
Posts: n/a
 
      6th Aug 2008
Why am I getting an Run time error 424 when trying to change the visible
properties in a control which is loaded into a collection. The collection is
dim'd as a Public variable. I am trying to change this property within a
click event of a button on the form

Public cntrlclctn1 As Collection

Private Sub CommandButton1_Click()
Dim x As Integer
For x = 1 To cntrlclctn1.Count
cntrlclctn1(x).Visible = True
Next

End Sub

Sub thing()
Dim lbl As Control
Dim txtbx As Control

'Create controls
Set lbl = UserForm1.Controls.Add("Forms.Label.1")
lbl.Caption = "Label Text"
lbl.Visible = False

Set txtbx = UserForm1.Controls.Add("Forms.TextBox.1")
txtbx.Text = "Text Box Text"
txtbx.Visible = False

'Add controls to collection
Set cntrlclctn1 = New Collection
cntrlclctn1.Add (lbl)
cntrlclctn1.Add (txtbx)

UserForm1.Show
End Sub
 
Reply With Quote
 
 
 
 
Jim Thomlinson
Guest
Posts: n/a
 
      6th Aug 2008
Remove the brackets...
Set cntrlclctn1 = New Collection
cntrlclctn1.Add lbl
cntrlclctn1.Add txtbx

With the brackets you are passing the default property instead of the object
itself...
--
HTH...

Jim Thomlinson


"ExcelMonkey" wrote:

> Why am I getting an Run time error 424 when trying to change the visible
> properties in a control which is loaded into a collection. The collection is
> dim'd as a Public variable. I am trying to change this property within a
> click event of a button on the form
>
> Public cntrlclctn1 As Collection
>
> Private Sub CommandButton1_Click()
> Dim x As Integer
> For x = 1 To cntrlclctn1.Count
> cntrlclctn1(x).Visible = True
> Next
>
> End Sub
>
> Sub thing()
> Dim lbl As Control
> Dim txtbx As Control
>
> 'Create controls
> Set lbl = UserForm1.Controls.Add("Forms.Label.1")
> lbl.Caption = "Label Text"
> lbl.Visible = False
>
> Set txtbx = UserForm1.Controls.Add("Forms.TextBox.1")
> txtbx.Text = "Text Box Text"
> txtbx.Visible = False
>
> 'Add controls to collection
> Set cntrlclctn1 = New Collection
> cntrlclctn1.Add (lbl)
> cntrlclctn1.Add (txtbx)
>
> UserForm1.Show
> End Sub

 
Reply With Quote
 
ExcelMonkey
Guest
Posts: n/a
 
      6th Aug 2008
Thanks Jim.

EM

"Jim Thomlinson" wrote:

> Remove the brackets...
> Set cntrlclctn1 = New Collection
> cntrlclctn1.Add lbl
> cntrlclctn1.Add txtbx
>
> With the brackets you are passing the default property instead of the object
> itself...
> --
> HTH...
>
> Jim Thomlinson
>
>
> "ExcelMonkey" wrote:
>
> > Why am I getting an Run time error 424 when trying to change the visible
> > properties in a control which is loaded into a collection. The collection is
> > dim'd as a Public variable. I am trying to change this property within a
> > click event of a button on the form
> >
> > Public cntrlclctn1 As Collection
> >
> > Private Sub CommandButton1_Click()
> > Dim x As Integer
> > For x = 1 To cntrlclctn1.Count
> > cntrlclctn1(x).Visible = True
> > Next
> >
> > End Sub
> >
> > Sub thing()
> > Dim lbl As Control
> > Dim txtbx As Control
> >
> > 'Create controls
> > Set lbl = UserForm1.Controls.Add("Forms.Label.1")
> > lbl.Caption = "Label Text"
> > lbl.Visible = False
> >
> > Set txtbx = UserForm1.Controls.Add("Forms.TextBox.1")
> > txtbx.Text = "Text Box Text"
> > txtbx.Visible = False
> >
> > 'Add controls to collection
> > Set cntrlclctn1 = New Collection
> > cntrlclctn1.Add (lbl)
> > cntrlclctn1.Add (txtbx)
> >
> > UserForm1.Show
> > End Sub

 
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
Change slides hidden property to visible programmatically Dale Fye Microsoft Powerpoint 2 13th Mar 2008 12:06 AM
Change visible property on an event =?Utf-8?B?U2F1cmFiaA==?= Microsoft ASP .NET 0 12th Sep 2006 11:56 PM
When I change field's visible property to false , error occurs . =?Utf-8?B?bWljaGFlbHM=?= Microsoft ASP .NET 0 1st Jun 2006 10:19 AM
Change ImageButton visible property in code dynamically Andy G Microsoft ASP .NET 4 20th Apr 2005 11:59 PM
What event to change a controls visible property =?Utf-8?B?QlQ=?= Microsoft Access Form Coding 4 24th Sep 2004 07:35 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:27 PM.