Version 1.2 Approx 0.66 MB (zipped) First Published 6 Nov 2023 Last Updated 8 Nov 2023
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:
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.
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.
Next, select all the controls in the Detail section and set the Back Style property to Transparent.
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.
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
The final step is to add conditional formatting to the txtColor textbox in the Detail section:
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
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()
2. I also use exactly the same idea in my emulated split form example app.
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.
Highlight Current Control
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 8 Nov 2023
Return to Example Databases Page
Return to Top