Example Apps for Businesses, Schools & Developers

Version 1.2         Approx 0.66 MB (zipped)                   First Published 6 Nov 2023                   Last Updated 29 Jan 2024

This is the first in a series of articles about highlighting objects on Access forms.

This article and example app was written in response to a questions at AccessForums.net: How to Highlight an entire row in a sub form in MS Access

In datasheet forms , the current record is automatically highlighted:

Datasheet Form
However, Access does not include a method of highlighting the current record in a continuous form.

As continuous forms use the same controls repeatedly for each record, you cannot just add colour to the individual controls.
Doing that would just cause all records to be highlighted!

However, highlighting can be done with a bit of trickery using one line of code and conditional formatting.

Continuous Form
This short video (0:12) demonstrates this effect in use:


Open your form in design view and add a hidden unbound textbox called e.g. txtCF anywhere on the form.

I've placed it in the header and coloured it red for the purpose of this article. However its never shown so its colour and location do not matter.

Design View 1
Next, select all the controls in the Detail section and set the Back Style property to Transparent.

Design View 2
Finally add another unbound textbox called e.g. txtColor to the Detail section.
Set it to be visible, with Back style as Normal and Back Color the same as the Detail section e.g. Background 1
Set its width equal to the form width and arrange it at the back BEHIND all other detail controls.

Design View 3
Now add the following line of code to the Form_Current event to set the hidden control txtCF value equal to the ID field of the current record:

Private Sub Form_Current()

      Me.txtCF = Me.ClassID       'replace with the ID field name from your own form

End Sub

The final step is to add conditional formatting to the txtColor textbox in the Detail section:

Conditional Formatting

As txtCF has been set equal to the current record value, this sets the highlight colour for the current record only.

1.   An unwanted side effect occurs if users click on a gap left between the controls as in the design view screenshots above.
      If that happens, the txtColor textbox gets focus and moves to the top of the z-order as shown below

txtColor Textbox Got Focus
      You can prevent this by setting txtColor locked & disabled in the property sheet & just enabling it in conditional formatting.
      However, that will cause another control in the detail section to get the focus and overlay the colour bar.

      To fix, either leave no gaps between the detail controls or, preferably, use code to move the focus again to another control such as the Close button if it happens.

Private Sub txtColor_GotFocus()
End Sub

2.   I also use exactly the same idea in my emulated split form example app.

Emulated Split Form


Click to download:   Highlight Current Record v1.2     Approx 0.65 MB(zipped)

Download and unblock the zip file.
For more details, see my article: Unblock downloaded files by removing the Mark of the Web

Unzip and save the ACCDB file to a trusted location.

More Continuous Form Examples

The following articles provide further examples of functionality added to continuous forms:

•   Highlight Selected Control or Column
•   Highlight Filtered Columns
•   Add Multiselect Filter   (2 pages)
•   Paint Me Transparent       (Selectively Hide Controls)
•   Sort columns
•   Hide duplicate values in a column   (as for reports)
•   Hide & Restore Selected Columns   (2 pages)
•   Freeze Columns   (3 pages)
•   Move and Resize Columns   (2 pages)

More Highlighting Examples

      Highlight Current Control in Single Form
      Highlight Required Fields
      Highlight Search Results


Please use the contact form below to let me know whether you found this article interesting/useful or if you have any questions/comments.

Please also consider making a donation towards the costs of maintaining this website. Thank you

Colin Riddington           Mendip Data Systems                 Last Updated 29 Jan 2024

Return to Example Databases Page

Return to Top