forecolor value

rikklaney1

Registered User.
Local time
Today, 13:55
Joined
Nov 20, 2014
Messages
157
a question about color coding a form. I have used this before

If Me.Text27.Value = "t" Then Me.Text27.ForeColor = 858083
If Me.Text27.Value = "p" Then Me.Text27.ForeColor = 55295
If Me.Text27.Value = "u" Then Me.Text27.ForeColor = 15643136

now the question.. is it possible to set a value for all the text boxes on the form with a single code block? Something like

If Me.Text*.Value = "t" Then Me.Text*.ForeColor = 858083
If Me.Text*.Value = "p" Then Me.Text*.ForeColor = 55295
If Me.Text*.Value = "u" Then Me.Text*.ForeColor = 15643136
 
Not like that, but can be done with a loop.

For X = 1 To 30

Me("Text" & X) = ...
 
Cool. that would be much simpler. Haven't learned loops yet. Guess that's what I'm learning today.
 
No problem; post back if you get stuck.
 
Could I do something similar with this block....

If Me.Text1.Value = "u" Then
If Me.code1.Caption = "s" Then Me.safety.Value = Me.safety.Value + Me.time1.Caption
If Me.code1.Caption = "i" Then Me.inspect.Value = Me.inspect.Value + Me.time1.Caption
If Me.code1.Caption = "t" Then Me.tighten.Value = Me.tighten.Value + Me.time1.Caption
If Me.code1.Caption = "c" Then Me.clean.Value = Me.clean.Value + Me.time1.Caption
End If
 
I can! That is awesome. I've been doing a lot of things with code justr because I was more comfortable with it. This is definitely a lot easier.
 
Check out the Select Case statement for this situation . . .
Code:
If Me.code1.Caption = "s" Then Me.safety.Value = Me.safety.Value + Me.time1.Caption
If Me.code1.Caption = "i" Then Me.inspect.Value = Me.inspect.Value + Me.time1.Caption
If Me.code1.Caption = "t" Then Me.tighten.Value = Me.tighten.Value + Me.time1.Caption
If Me.code1.Caption = "c" Then Me.clean.Value = Me.clean.Value + Me.time1.Caption
. . . becomes . . .
Code:
    Select Case Me.code1.Caption
        Case "s"
            Me.safety = Me.safety + Me.time1.Caption
        Case "i"
            Me.inspect = Me.inspect + Me.time1.Caption
        Case "t"
            Me.tighten = Me.tighten + Me.time1.Caption
        Case "c"
            Me.clean = Me.clean + Me.time1.Caption
    End Select
 
A bit cleaner for sure. How about this one...

For x = 1 To 35
If Me("label" & x).Value < Me.run.Caption Then Me("label" & x).BackColor = 3329330
Next


it works except it seems to pick up the first number. If run is 6 the 1 thru 5 are green but so are 10 thru 35. Should I just double the x to XX?
 
also for the case..

for x = 1 to 35

Select Case Me("code" &x).Caption
Case "s"
Me.safety = Me.safety + Me("time" & x).Caption
Case "i"
Me.inspect = Me.inspect + Me("time" & x)Caption
Case "t"
Me.tighten = Me.tighten + Me("time" & x)Caption
Case "c"
Me.clean = Me.clean + Me("time" & x)Caption
End Select


and that would work for all 35? I hope?
 
I suspect it's interpreting the values as text. You might try wrapping form references in a conversion function such as CInt().
 

Users who are viewing this thread

Back
Top Bottom