Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 553
Default 424 Error whem trying to change Visible property

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default 424 Error whem trying to change Visible property

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 553
Default 424 Error whem trying to change Visible property

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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Runtime error 1004 - unable to set Visible property of Worksheet c SueJB Excel Programming 2 October 4th 05 02:27 PM
Error:Unable to set the visible property of the PivotItem class. Holger Pietsch Excel Programming 2 August 16th 05 05:11 PM
.visible property causing an error in Excel 97 John Excel Programming 0 July 5th 04 04:00 PM
Visible Property Steve A[_2_] Excel Programming 1 January 5th 04 12:35 PM
Run-time error '1004' - Unable to set the Visible property of the Worksheet class Shalin Chopra Excel Programming 3 November 25th 03 08:38 PM


All times are GMT +1. The time now is 01:37 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"