Overview
Make it easier to see the current record on your Microsoft Access forms! To highlight the current record with a yellow background color, use Conditional Formatting, a control to keep track of the primary key value, a control to change color, and a little VBA. See how it works in this video:
While designing, I like to increase the height of the detail section, create a shorter txtHighlight control below everything else on the ruler, set all the properties, then move txt Highlight up, close the height of the detail section, and then set the Height of txtHighlight to whatever the section turns out to be.
Once the controls are created, write VBA code and set Conditional Formatting.
MyPrimaryKey is the name of your primary key control such as ProductID, OrderID, ContactID, etc. The expression in a Conditional Formatting rule can refer to control names or field names.
If you are using a datasheet form instead of a continuous form, you can't have a control under all the others, so set the conditional formatting rule on every control. You can then select all the textboxes and set the rule.
To specify code for an event
- select the object you want such as the form or a control
- go to the Event tab of the property sheet
- choose [Event Procedure] or pick it from the list -- or just type "[" to pick [Event Procedure]
- Click the builder button [...], or press Ctrl+F2, to go to the Visual Basic Editor
- Access will automatically create the Sub declaration and End Sub Statements.
- Type what you want to happen between the procedure declaration and End statements.