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
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