Remember Me
forgot your password?

Ms Access Tutorial - How to Use Color Coding to Enhance your Applications

Please take a look at this powerful technique to add advanced color coding logic to your forms.

Color coding adds value to a form as it easily directs the user's eye to critical data. This is a powerful technique that allows a user to quickly evaluate a pages of data for errors or warning information.

Access 2000 to Access 2003 has a limit of four colors you can use for each field on a continuous form. Using the condition code methos described in this tip, there is no limit to the logic you can apply to set the field conditions to one of the four color options.

Create a table name it ColorCoding
Enter the following fields (without the numbers)
1] CntrID as Autonumber, make it the primary key field
2] Cntname as text
3] WorkDesc as text - the data should either be "min" or " maj"
4] EMR as number, single - the data should be any integer between 1 and 10
5] aggdate as date/time
6] aggamnt as currency
7] wcompdate as date/time
8] wcompamnt as currency
9] concode as number, long integer this field will be calculated so leave it blank.

Enter some data in the table for testing.

Create a form continuous style form using the ColorCoding table as the data source.
Add a form header/footer.
Put a form title in the form header section of the form (optional).
Use the other tab on the properties form and give each field the same name as it's control source. So, name the [EMR] field "EMR" for example. Then you Can use the field names like variable names when you create VBA code.
Add all the fields to the table and align the in one row with the field labels above each field but in the form header sectionof the form.
This should leave one row of fields in the detail section of the form.
Put a button in the footer with the caption refresh.

In design mode on your form, choose Format / Conditional Formating.
Use the Mid command to check a character in the condition code and set your condition colors. Look at the [EMR] field. It is the fourth field from the left. The Mid command directs Access to check the field concode in the fourth chracter place for a span of 1 character for the value of 3.
Set the conditions like this

Leave the default formatting set to white background and black font color.

Expression is Mid([concode],4,1)="3" Pick a color -- I use Red for 3 or an failing condition

Expression is Mid([concode],4,1)="2" Pick a color-- I use yellow for 2 or a warning condition

Expression is Mid([concode],4,1)="1" Pick a color -- I use green for 1 or a passing condition

Repeat this for each field you wish to set conditions on. Note that each character of the condition code starting from left to right will represent a respective field from left to right. So, a 3 in the 2 place on the condition code field will set the CntName field to red. See the field numbers above. Subsequent fields follow the same sequence.

One more example for the [aggdate] field the condtional format would look like:
Expression is Mid([concode],5,1)="3" Pick a color. This

The condition code field, [concode], values are created with any logic that you want to assign to it. In this example I am using eight fields so the conidition code is eight characters wide and each character could be either a 0,1,2, or 3. So it may look like this 10112321. Now using the mid command above, the fourth character is a 1 so the condition for the fourth field,[ EMR], would be a 1 which conditions to green.

Once you have the form designed and tested, you may want to go back and set the concode field to invisible. Your users don't need to see that data.

After you have created the form apply the following code. You can cut and paste this right into the form if you used the same field names described without any typing.

Cut here --------
Option Compare Database
Dim rec As DAO.Recordset
Dim db As Database

Public Function SetConCode()
On Error GoTo erout
Dim xcode(10) As Integer, x As Integer, CCode As String, y As Integer
' xcode values 1 = green, 2 = yellow, 3 = red, 0 =white
' Use the next line if you have hundreds of records and don't want to wait on the screen to update
'DoCmd.Echo False
'Set the field counter to Zero
x = 0
'increment the field counter as you go
x = x + 1 'Step 1
If IsNull(CntrID) Then
xcode(x) = 0
Else
xcode(x) = 1
End If

x = x + 1 'Step 2
If IsNull(Cntname) Then
xcode(x) = 0
Else
xcode(x) = 1
End If

x = x + 1 'Step 3
If IsNull(WorkDesc) Then
xcode(x) = 0
Else
xcode(x) = 1
End If

x = x + 1 'Step 4
If IsNull(EMR) Then
xcode(x) = 0
ElseIf EMR 3 And EMR <= 7 Then
xcode(x) = 2
Else
xcode(x) = 3
End If

x = x + 1 'Step 5
If IsNull(aggdate) Then
xcode(x) = 0
ElseIf aggdate = Now() And aggdate <= Now() + 10 Then
xcode(x) = 2
Else
xcode(x) = 1
End If

x = x + 1 'Step 6
' You can use any amount of logic you need to set the condition you want and then drive
' the conditional formatting to the color you desire.
' In this example I use two sets of condition values depending on the value of another field alltogether.
If IsNull(aggamnt) Then
xcode(x) = 0
GoTo aggout
End If
If WorkDesc = "min" Then
If aggamnt = 1 And aggamnt <= 5 Then
xcode(x) = 2
Else
xcode(x) = 1
End If
GoTo aggout
ElseIf WorkDesc = "maj" Then
If aggamnt = 3 And aggamnt <= 7 Then
xcode(x) = 2
Else
xcode(x) = 1
End If
End If
aggout:

x = x + 1 'Step 7 wcompdate
If IsNull(wcompdate) Then
xcode(x) = 0
ElseIf wcompdate = Now() And wcompdate 1 Then
xcode(2) = 3
End If

'Build conCode field values from xcode values collecting the value of X from left to right
'
y = 0
For y = 1 To 8
If y = 1 Then
CCode = xcode(y)
Else
CCode = CCode & xcode(y)
End If
Next
'MsgBox "setconcode finished"
concode = CCode
erout:
Debug.Print Err.Description
DoCmd.Echo True

End Function

'Run the SetConCode function after each field is updated

Private Sub addamnt_AfterUpdate()
SetConCode
End Sub

Private Sub aggdate_AfterUpdate()
SetConCode
End Sub

Private Sub Cntname_AfterUpdate()
SetConCode
End Sub

Private Sub EMR_AfterUpdate()
SetConCode
End Sub

Private Sub Form_Open(Cancel As Integer)
'Loop through all the records setting the concode values when the form is opened to check date values.
Dim x As Integer

x = 1
Set rec = Me.Recordset.Clone
rec.MoveLast
If rec.RecordCount = 0 Then
MsgBox "NO Records Found"
End If
rec.MoveFirst
DoCmd.GoToRecord acDataForm, "CondCodes", acFirst
For x = 1 To rec.RecordCount - 1
If x = rec.RecordCount Then
GoTo getoutloop
Else
SetConCode
DoCmd.GoToRecord acDataForm, "CondCodes", acNext
End If
Next
getoutloop:
rec.Close
End Sub

Private Sub set_Click()
'Loop through all the records setting the concode values
Dim x As Integer

x = 1
Set rec = Me.Recordset.Clone
rec.MoveLast
If rec.RecordCount = 0 Then
MsgBox "NO Records Found"
End If
rec.MoveFirst
DoCmd.GoToRecord acDataForm, "CondCodes", acFirst
For x = 1 To rec.RecordCount - 1
If x = rec.RecordCount Then
GoTo getoutloop
Else
SetConCode
DoCmd.GoToRecord acDataForm, "CondCodes", acNext
End If
Next
'DoCmd.Echo True ' turn echo back on if you turned it off
getoutloop:
rec.Close
End Sub

Private Sub wcompamnt_AfterUpdate()
SetConCode
End Sub

Private Sub wcompdate_AfterUpdate()
SetConCode
End Sub

Cut Here --------------

You can download the example database file from our site at www.biomationsystems.com. Look for the Access Tips link.

This example was created with Access 2002. There may be better ways to accomplish the same thing, but this works well for us. You will need to set the VBA references to include microsoft DAO 3.6

This should do it. You can find the complete example on our web site with a sample database included.

Please note that this is a powerful and valuable tip that can help you set your database applications apart and make your users want more. We work hard to provide these tutorials and would very much appreciate you visiting our site and taking a look at our site and giving us some feedback.

We develop custom applications that solve complex data problems for businesses of all sizes. Our users ask us back because we provide great value. We are looking for partners in process improvement.

If you know of anyone who would benefit from this type of Access help, please feel free to pass this email along.

We have combined two of our favorite utilities into one great limited time special offer. The email tool that we use to keep in touch with our customers and a backup scheduler that allows you to schedule your data to be safely backed up in two different locations.

One Day...

Jon E. Watson
President, BioMation Systems, Inc.
Look for our products and services at www.biomationsystems.com

Jon Watson

Jon Watson is the founder of Biomation Systems, Inc. With 26 years experience helping Fortune 500 companies with process improvement he formed BioMation to bring the same expertise to smaller companies that need the same improvements at an affordable price.
You can find more help for MS Access at:
www.biomationsystems.com
www.accessdatabasehelp.com
www.accesshelpebook.com

Rate this Article: 0 / 5 stars - 0 vote(s)
Print Email Re-Publish

Add new Comment



Captcha

  • Latest Management Articles
  • More from Jon Watson

Middleman System New Review December 31st

By: Clare Clements | 31/12/2009
Aymen and his team at former Arbitrage Conspiracy have released Middleman System on December 17th, through a Special Webcast ,with Guesr Brian Tracy what is to be the Biggest Launch in the Internet marketing History.

Why Virtual CFOs Have to Be Better, Faster and Smarter

By: Scott A. McPherson, CPA, CFG, CVA | 31/12/2009
There’s no doubt that the realm of the CFO has shifted dramatically. And by some economic and marketplace indicators, dynamic virtual CFOs, especially those who specialize in partnering with small and mid-sized businesses, could become the next generation of chief financial officer professionals. That is, as long as those virtual CFOs stay better, faster and smarter.

ERP Software: Increase the Efficiency of Your Engineering Department

By: S. Daggle | 31/12/2009
Manufacturing companies rely on their engineering department in order to secure a profit. While the sales department initiates leads, the engineering department is in charge of creating products and filling orders which ultimately results in the sale and revenue. This means that the efficiency of your engineering department directly affects...

How Do I Earn Extra Incomes - Extra Incomes With Style

By: Rok Pisek | 31/12/2009
Do you need extra income and are you willing to have it? We are talking about extra income to develop your lifestyle level or even to give a chance to quit your current work and start to work on internet which can make your life easier. Of course there exists many...

What makes a toddler an entrepreneur?

By: Kim Roddy | 31/12/2009
There are numerous fables of people who have risen from to being a downtrodden person to an entrepreneur. These are the people who were once an employee and after conquering a series hardships and adversities of life they attain the position where they generate employment for others and become a source of inspiration for the society and for who strive to be successful

Global Warehouse Management Systems (WMS) Market in Retail Industry

By: Bharat Book Bureau | 31/12/2009
Bharatbook.com added a new report on "Global Warehouse Management Systems (WMS) Market in Retail Industry 2008-2012" into its market report catalogue for reselling.

When Employee Conflict Gets Ugly

By: Imelda Bickham | 31/12/2009
Employee conflict can be healthy when it aims at resolving differences and finding a common ground. Conflict becomes harmful when it aims at winning, and proving that one is right and the other person is wrong.

Various Tips To Avoid Common Errors In Real Estate Investing

By: Sabrina Jose | 30/12/2009
Real estate investing is generally thought of to be a method of getting rich quickly. So, people feel that they can definitely make a lot of money by investing in real estate. This can lead to a lot of errors being made. If you are aware of the errors it will be easy to avoid them.

Ms Access Tip – you Have Heard ofs, Now Learn to Use Them

By: Jon Watson | 11/01/2008 | Management
This example demonstrates using an array and SQL statements to create the similar records. It also has a function to replace records if you want to change the amount value and update the data table. The replace function assumes that the description and date are the same and replaces every occurrence of the existing record with the latest amount value. For safekeeping the replace function makes a copy of the data table before executing.

Ms Access Tutorial - How to Use Color Coding to Enhance your Applications

By: Jon Watson | 18/12/2007 | Management
Color coding adds value to a form as it easily directs the user's eye to critical data. This is a powerful technique that allows a user to quickly evaluate a pages of data for errors or warning information.

How to Get the Most From your Training Dollar

By: Jon Watson | 12/12/2007 | Management
There are so many people telling you that you can make such a huge return on your investment these days that you just can't believe any of them any longer. I know, I have received so many get rich emails that I should be earning about a billion a day now! How about investing in something that you really believe in. Yourself.

Ms Access Tip: Self Learning Combo Box

By: Jon Watson | 12/11/2007 | Technology
Database data entry can be tedious at times. You can make your databases more user friendly if they have a way to select data to enter rather than typing in the same data over and over. Access provides a form control called a combo box to help with this task but it can lead to trouble.

Access Databasetip: Create a User Defined Search Field for a List Box

By: Jon Watson | 02/11/2007 | Technology
Many times it is necessary to provide your users with an easy way to filter or search for data in large table of information. This tip will show you one quick and easy way to solve the problem by giving the user a field to enter a search string and updating the form with those fields that fit the search pattern. It's quick and easy, so give it a try. Read about how Access was a big success solving a license tracking issue in this article.

Access Database Tip: How to Multiselect in a Listbox

By: Jon Watson | 26/10/2007 | Technology
When you have a list box it is handy to be able to multiselect to perform some action on multiple items in the listbox. Here is a simple set of instructions to get you started. These instructions will create a quick way to multiselect and delete rows from a table.

Ms Access Tip: Keeping Up With User Activity

By: Jon Watson | 25/10/2007 | Technology
At times you will find it very handy to know what a user was doing in your application at a specific time. This is especially useful with multi-user database applications for debugging or security reasons. With this tool implemented in your applications you will be able to see what event happened and at what time.

Submit Your Articles Free: Signup

Use of this web site constitutes acceptance of the Terms Of Use and Privacy Policy | User published content is licensed under a Creative Commons License.
Copyright © 2005-2008 Free Articles by ArticlesBase.com, All rights reserved. (0.27, 6, w3)