Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Changing the color of a label on a form when there are many labels

Posted on 2004-10-24
7
Medium Priority
?
188 Views
Last Modified: 2010-05-02
I am working with a form that has 65 small labels on it. I want to change the color of them to some color that is not in the backcolor pulldown. Putting in 65 lines of code all looking like

userform3.label1.backcolor=rgb(240,100,0) is a night mare

because I want to pole these labels for more important information. Is there a for each command that I can set up.
0
Comment
Question by:jcherry_99
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 28

Assisted Solution

by:vinnyd79
vinnyd79 earned 400 total points
ID: 12395059
Have you considered putting them into a control array. You could then use:

Private Sub Command1_Click()
Dim i As Integer
For i = 0 To UserForm3.Label1.Ubound
    UserForm3.Label1.Item(i).BackColor = RGB(240, 100, 0)
Next i
End Sub
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 400 total points
ID: 12395072
or
For each ctl in UserForm3.Controls
    if left$(ctl.name,5) = "Label" then
           ctl.BackColor = RGB(240, 100, 0)
   endif
next ctl

Incidentally how does one 'pole' anything, label controls included?
0
 

Author Comment

by:jcherry_99
ID: 12395291
I am perfectly happy with the second answer. I've tried it and it works. But before signing off on the question, I'd like to ask something on the first (I'll increase the number of points).

1. what are you clicking to get to the subroutine you've typed.
2. How do you make the array? I'm not sure I know how to do that.


Thank you both so much for your quick response.

Jerome
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 76

Expert Comment

by:GrahamSkan
ID: 12395345
Hi Jerome
The best place to put the code is somewhere which gets run early in your program run. That is probably in your initial Form_Load event. You won't have to click anything.
Graham
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 12395383
Sorry, that means
Sub Form_Load '(in Userform3)
For each ctl in Me.Controls
    if left$(ctl.name,5) = "Label" then
           ctl.BackColor = RGB(240, 100, 0)
   endif
next ctl
end sub

0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 12395437
To create an array you would add a label and set the index property to 0. Then you would add more labels with the same name and they would each have a different index.They can then be referred to by index #.

Label1(0).Caption = "Label 1 Text"
Label1(1).Caption = "Label 2 Text"
Label1(2).Caption = "Label 3 Text"

The advantage to this is that a VB form can only contain 255 controls.By adding them into a control array,all 65 Labels will count as 1.
0
 
LVL 5

Expert Comment

by:KarcOrigin
ID: 12396371
Hi,
Although you are satisfied with GrahamSkan comments here I am with one more way to do that-

Private Sub Form_Load()
    Dim obj As Object
    For Each obj In Me.Controls
        If TypeName(obj) = "Label" Then
            obj.BackColor = RGB(240, 100, 0)
        End If
    Next
End Sub

Cheers!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question