tkschultz1207
asked on
Change the background color of a textbox in MS Access if the values in the two text boxes do not equal each other.
I have two text boxes named: Var_No and Old_Var_No on a form. The form is attached to a table and I am using the record selectors to scroll thru the table.
I want the background color of Var_No to turn red if the value in Var_No does not equal Old_Var_No.
I wrote the following code but it doesn't work, I put the code under the Load event on the form. Sometimes the fields don't have data in them so it needs to handle NULL any ideas would be appreciated.
I want the background color of Var_No to turn red if the value in Var_No does not equal Old_Var_No.
I wrote the following code but it doesn't work, I put the code under the Load event on the form. Sometimes the fields don't have data in them so it needs to handle NULL any ideas would be appreciated.
Private Sub Form_Load()
Dim lngRed As Long
Dim lngWhite As Long
lngWhite = RGB(0, 0, 0)
lngRed = RGB(255, 0, 0)
Me.VAR_NO.BackColor = lngWhite
If Me.VAR_NO <> Me.OLD_VAR_NO Then
Me.VAR_NO.BackColor = lngRed
ElseIf (IsNull(Me.VAR_NO) = True And IsNull(Me.OLD_VAR_NO) = False) Then
Me.VAR_NO.BackColor = lngRed
ElseIf (IsNull(Me.VAR_NO) = False And IsNull(Me.OLD_VAR_NO) = True) Then
Me.VAR_NO.BackColor = lngRed
ElseIf (IsNull(Me.VAR_NO) = True And IsNull(Me.OLD_VAR_NO) = True) Then
Me.VAR_NO.BackColor = lngWhite
ElseIf Me.VAR_NO = Me.OLD_VAR_NO Then
Me.VAR_NO.BackColor = lngWhite
End If
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
why not just use Format >COnditional Formatting in the design view of your form
select the Controls first then Format >conditional formatting
select the Controls first then Format >conditional formatting
ASKER
Works. Thanks
mx