Access-Macro: Change all text to be a color based on a checkbox
In my access database, there is a Yes/No field named "No Longer Viable", and appropriatley, there is a No_Longer_Viable checkbox in my form. Whenever the data is loaded, and the box is checked or whenever they check the box during data entry, I want to change the text color of all other textboxes to be blue.
VB Code:
Private Sub Form_AfterUpdate()
ChColor
End Sub
Private Sub Form_DataChange(ByVal Reason As Long)
ChColor
End Sub
Private Sub Form_DataSetChange()
ChColor
End Sub
Private Sub Form_Load()
End Sub
Private Sub Form_ViewChange(ByVal Reason As Long)
ChColor
End Sub
Private Sub No_Longer_Viable_Click()
ChColor
End Sub
Sub ChColor()
If Me.No_Longer_Viable.Value <> 0 Then
For Each x In Controls
x.ForeColor = vbBlue
Next x
Else
For Each x In Controls
x.ForeColor = vbBlack
Next x
End If
End Sub
If you know how to only change the textboxes blue instead of the labels as well, i would prefer that. I tried doing If not IsNull(x.text) then... but I got an error saying I can't retreive the value of an object if it isn't in focus. Maybe I could set the focus to the item first and then check it. Hm.
Thank you for any help,
James