Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change a labels colour from the value in a textfield 1

Status
Not open for further replies.

bfamo

Technical User
Feb 16, 2006
132
NO
Hey you guys.

I have, with great help from Zion7, made a form with a text field "txtAvg" that shows the average value from 3 option groups. This works just fine.
However, after some testing I have found out that I also need a lable that changes color from blue to red when the value of the text field is higher or lower than 30. Let's call the lable "LblWarning".

The code of the function is as follows:

Function AvgSum() As Double
Dim intCount As Integer
Dim dblSum As Double, y As Integer

For y = 1 To 3
If Me("Grp" & y) <> 0 Then
intCount = intCount + 1
dblSum = dblSum + Me("Grp" & y).Value
End If
Next y

If intCount <> 0 Then
dblSum = dblSum / intCount
AvgSum = Format(dblSum, "Fixed")
Else
AvgSum = 0
End If

End Function

Private Sub Grp1_Click()
txtAvg = AvgSum
End Sub

Private Sub Grp2_Click()
txtAvg = AvgSum
End Sub

Private Sub Grp3_Click()
txtAvg = AvgSum
End Sub

Private Sub Form_Current()
txtAvg = AvgSum
End Sub


I have tried to write some code into the Form_Current event like this:

If txtAvg < 30 Then
LblWarning.ForeColor = vbBlue
Else
LblWarning.ForeColor = vbRed
End If

This does not respond the way I want it to, actually it does not respond at all.

So, does anyone know how to sort this thing out?

Thanks ;)
 
Why not setting the color in the AvgSum() function ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
yeah I could to that... with som help :D
How would you do that ?
 
How are ya bfamo . . .

Transfer your [blue]IF[/blue] statement to the end of your [blue]AvgSum[/blue] function:
Code:
[blue]Function AvgSum() As Double
    Dim intCount As Integer
    Dim dblSum As Double, y As Integer

    For y = 1 To 3
        If Me("Grp" & y) <> 0 Then
            intCount = intCount + 1
            dblSum = dblSum + Me("Grp" & y).Value
        End If
    Next y

    If intCount <> 0 Then
      dblSum = dblSum / intCount
      AvgSum = Format(dblSum, "Fixed")
    Else
      AvgSum = 0
    End If

    [purple]If [b]AvgSum[/b] < 30 Then
        LblWarning.ForeColor = vbBlue
    Else
        LblWarning.ForeColor = vbRed
    End If[/purple]

End Function[/blue]

Calvin.gif
See Ya! . . . . . .
 
Thanks alot man!
Works fine now!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top