Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
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
Medium Priority
?
712 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 15

Accepted Solution

by:
MNelson831 earned 2000 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
 

Author Closing Comment

by:tkschultz1207
ID: 31567696
Works. Thanks
0

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

705 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