Setting a Label's BackColor by Code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

No problem setting a textbox's BackColor by code, but...

i'm using in...
Private Sub ReportHeader_Format(Cancel As Integer, FormatCount As Integer)

....snippet...
Where B and C are Doubles...
B = CDbl(AShrink.Caption): C = CDbl(ATotalRepair.Caption)
lbl433.Caption = Format((B / C) * 100, "#0.0") & "%"
If IsNumeric(Left(lbl433.Caption, 2)) Then
I = CInt(Left(lbl433.Caption, 2))
If I >= 10 Then lbl433.BackColor = 255
End If

It WILL run the "...If I >= 10 Then lbl433.BackColor = 255",
but the BackColor (on one label ONLY...the others work properly)
will be white when the Report opens.

Ideas...please.

TIA - Bob
 
Hi Bob

Why not copy a lable that does work and change the code to reference this
new lable and see if this works - worth a try
 
Wayne-I-M....I tried it...and instead of naming the copied label
"lbl267", I kept "Label267", and...

It WORKED...now...why? Is this a "fix" from your experience???

Thank you - Bob
 
Ha Ha LoL

No

But sometime things are just "bust". So it sometimes helps to simply press
the delete button. Of course there is normally a good reason why thing don't
work - but (this is my expereince) something just are not wrth the time
worrying about. If you can get them to work - fine, if not then it may be
worth looking at in more details.

Glad it worked for you
 
Thanks again...This is going into "My Tool Bag"...
IF it doesn't work someday, we'll try for another solution.

Bob
 
Hi Bob

I created a butoon called LableGoAway and used both of your lable names to
see if there was anything there that would have caused the problem you
descibed and it didn't so I don't think it was the name that was causeing the
problem. Without looking at the other - interrelated - codes and controls,
on your form there is not a lot I can say other than if it works now thats
good but if it doesn't work in the future you could repost with more details.

Create a button LableGoAway and lables Label186 and lbl186 and use this
OnClick of the button to test the names.

Private Sub LableGoAway_Click()
If Me.lbl186.Visible = True Then
Me.lbl186.Visible = False
Else
Me.lbl186.Visible = True
End If

If Me.Label186.Visible = True Then
Me.Label186.Visible = False
Else
Me.Label186.Visible = True
End If
End Sub

As you can see - clicking again and again on the button hides and unides the
lables so not much there to cause the problem
 
Back
Top