Solved

Change the background color of a textbox in MS Access if the values in the two text boxes do not equal each other.

Posted on 2009-04-07
5
696 Views
Last Modified: 2013-11-28
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.
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

Open in new window

0
Comment
Question by:tkschultz1207
5 Comments
 
LVL 15

Accepted Solution

by:
MNelson831 earned 500 total points
ID: 24090832
Put the code in the OnCurrent event

0
 
LVL 75
ID: 24090836
Have you considered Conditional Formatting to do this ?

mx
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 24090847
why not just use Format >COnditional Formatting  in the design view of your form

select the Controls first then Format >conditional formatting
0
 
LVL 75
ID: 24090879
0
 

Author Closing Comment

by:tkschultz1207
ID: 31567696
Works. Thanks
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Access 2003 query lost it's only join 7 27
Access Open Report with SQL Parameter 11 31
is Microsoft Access going to Die? 9 53
DCount Type Mismatch 2 22
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question