Skip to content

Setting the current row back colour

How to make the current row a different color for continuous forms or datasheet type subform (and for continuous forms-type main forms).

Access Archon #173


Introduction

When you have a form with a continuous forms or datasheet type subform, sometimes it is a good idea to highlight the current row by making its background a different color.  In this article I will show how to make the current row a different color for both of these types of subforms (and for continuous forms-type main forms), using different techniques.

The first sample form is frmBackColorContinuousFormsMatchComboBox, a continuous forms-type form.  This form has a typical record selector combo box in its header, where the user can select a record.  Once a record is selected, the matching row’s back color changes to orange:

Figure A.  A continuous forms-type form with a different back color for the selected row

The back color change is done using the Conditional Formatting feature introduced in Access 2000.  Form sections don’t support this feature, so I placed a large textbox control in the Detail section, behind the other controls, with Tab Stop set to No, and Locked to Yes (so the user can’t click on it to give it focus, which would hide the other controls).  I right-clicked the txtBackfill textbox, and selected Conditional Formatting from the context menu, to open the Conditional Formatting dialog.  I selected Expression Is in the drop-down list, and entered the expression shown, which evaluates to True for the row that matches the combo box selection; I then selected the color from the color selector, and clicked OK.

Figure B.  Entering an expression in the Conditional Formatting dialog

The other main form in the sample database, frmBackColorDemo, has two subforms:  the top one is a continuous forms-type subform and the bottom one is a datasheet subform.  The continuous forms-type subform uses a similar technique to frmBackColorContinuousFormsMatchComboBox, except that it matches the current record to a textbox in the subform’s header (which is not visible).  The unbound textbox (txtSelectedCategoryID) has its value set from the Current event of the subform.

The datasheet-type subform uses a different technique:  since the controls fill the datasheet entirely, I created conditions for both the textboxes, using the condition

[txtSelectedCategoryID].Value=[txtCategoryID].Value

 

The result is that both textboxes change color for the selected row, as shown below:

Figure C.  A form with a continuous forms-type subform and a datasheet subform

Using one or another of these techniques, you can ensure that users of a database will know which row is selected, something that may not be obvious otherwise.


References

The code in the sample database does not need any special references.


Supporting Files

The zip file containing this article, in Word 97-2003 format, plus the supporting file(s), may be downloaded from the Access Archon page of my Web site, as accarch173.zip, which is the last entry in the table of Access Archon columns for Access Watch.











Document Name

Document Type

Place in

Current Record Back Color (AA 173).mdb

Access 2002-2003 database (can also be used in higher versions of Access)

Wherever you want

About this author