Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 112
Default Grouping controls

Is it possible to group specific controls from other controls of the same
type in a Userform? I cannot use a Frame because the controls are in
different locations in the form! Let's say that I want to set a specific
bunch of labels with red forecolour when a certain condition is met (pressing
a button f.i.) but all the other labels stay
with black forecolour. Another issue would be to disable a bunch of
Textboxes that
are not related to the current task in the UserForm.
I tried to manipulate their Name, ex. ALabel1, BLabel1, ALabel2,
BLabel2....etc.
and then refer to the names as group of controls, but I'm not certain how to
accomplish this, so I better ask you experts out there!
Best regards
Mats
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Grouping controls


"Mats Samson" wrote in message
...
Is it possible to group specific controls from other controls of the same
type in a Userform? I cannot use a Frame because the controls are in
different locations in the form! Let's say that I want to set a specific
bunch of labels with red forecolour when a certain condition is met

(pressing
a button f.i.) but all the other labels stay
with black forecolour. Another issue would be to disable a bunch of
Textboxes that
are not related to the current task in the UserForm.
I tried to manipulate their Name, ex. ALabel1, BLabel1, ALabel2,
BLabel2....etc.
and then refer to the names as group of controls, but I'm not certain how

to
accomplish this, so I better ask you experts out there!


Using a naming convention:

I added three textboxes to a form and called them txtAName, txtAAddress and
txtBAge. Then I created the following test routine.

Private Sub CommandButton1_Click()
Dim obj As Control
Dim objT As MSForms.TextBox
For Each obj In Me.Controls
If TypeOf obj Is MSForms.TextBox Then
If Left(obj.Name, 4) = "txtA" Then
Set objT = obj
objT.BackColor = vbYellow
End If
End If
Next
End Sub

Works fine for me.

Robert


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 112
Default Grouping controls

Thanks a lot Robert,
it did exactly what I wanted!
And I even cut it to selecting a group of different controls with a "coded"
namelabel:
Dim obj As Control
For Each obj In Me.Controls
If Left(obj.Name, 2) = "Pu" Then
obj.Enabled = True
End If
Next
By coding the Label Name I can get any control to belong to several groups
(selections) by using Left(obj.Name, n) = "?", i.e. if n=2, PuRLabel10 and
PuSLabel19 belongs to the same selection but if n=3, they are in different
groups! Very neat, but needs of course a careful planning when naming the
labels.
Best regards
Mats

"Robert ap Rhys" wrote:


"Mats Samson" wrote in message
...
Is it possible to group specific controls from other controls of the same
type in a Userform? I cannot use a Frame because the controls are in
different locations in the form! Let's say that I want to set a specific
bunch of labels with red forecolour when a certain condition is met

(pressing
a button f.i.) but all the other labels stay
with black forecolour. Another issue would be to disable a bunch of
Textboxes that
are not related to the current task in the UserForm.
I tried to manipulate their Name, ex. ALabel1, BLabel1, ALabel2,
BLabel2....etc.
and then refer to the names as group of controls, but I'm not certain how

to
accomplish this, so I better ask you experts out there!


Using a naming convention:

I added three textboxes to a form and called them txtAName, txtAAddress and
txtBAge. Then I created the following test routine.

Private Sub CommandButton1_Click()
Dim obj As Control
Dim objT As MSForms.TextBox
For Each obj In Me.Controls
If TypeOf obj Is MSForms.TextBox Then
If Left(obj.Name, 4) = "txtA" Then
Set objT = obj
objT.BackColor = vbYellow
End If
End If
Next
End Sub

Works fine for me.

Robert



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
grouping Radio Buttons; Using ActiveX Controls ryguy7272 Excel Discussion (Misc queries) 2 May 6th 10 06:01 PM
ActiveX Controls vs Form Controls Alex Excel Discussion (Misc queries) 1 January 11th 06 08:46 AM
How to unprotect Grouping controls Bob Laithwaite Excel Worksheet Functions 1 May 18th 05 01:32 AM
Event procedures for controls added with Controls.Add John Austin[_4_] Excel Programming 1 March 9th 05 03:31 PM
Grouping Userform Controls ExcelMonkey[_190_] Excel Programming 1 February 23rd 05 02:49 PM


All times are GMT +1. The time now is 08:42 AM.

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

About Us

"It's about Microsoft Excel"