Versions 1.1 / 1.3 Approx 0.9 MB (zipped) First Published 20 May 2025 Last Updated 12 Jun 2025
In a previous article, Highlight Current Record in Continuous Form, I showed how the current record could be highlighted using just one line of code together with conditional formatting.
In a separate article,Paint Me Transparent, I demonstrated how individual controls in a continuous form could be hidden using the transparency property of command buttons.
In this article, I will combine these ideas to show how transparency can be used to highlight the current record in a continuous form.
More accurately, I will show how the current record can be highlighted by disabling transparency for a button border.
To achieve the above effect, add a command button to the detail section of the form and change its shape to use e.g. rounded corners.
Adjust the size and height of the button to match that for the form detail.
Now set the button back style to transparent and the border style to solid. I have used a border width = 2pt and a green border color.
Each record MUST have a unique field, in this case PupilID. The field can be hidden if preferred.
A hidden unbound textbox, RecNo, is also required. Place this anywhere on the Detail section.
Add the following code to your form:
'set current recordPrivate FunctionSetRecordHighlight()RecNo=PupilIDEnd FunctionPrivate SubDetail_Paint()'set border transparent for all except the current recordMe.cmdHighlight.Transparent=RecNo<>PupilIDEnd Sub
Also set the button GotFocus event to the function SetRecordHighlight:
When the user clicks anywhere on a record to make it the current record, the button GotFocus event fires and sets the value of the hidden control RecNo equal to the PupilID.
The Detail_Paint event then runs and sets the button transparent for all records except the current record. In other words, for all records where RecNo <> PupilID.
For the current record, the button transparency is set false. However this only makes the button border solid green as the back style remains transparent.
NOTE:
As an alternative, you can use a rectangle (box) control instead of a command button. This will have square corners. However, the box control has a wider choice of border styles e.g. dot-dash
In this example, the following code is used:
'set current recordPrivate FunctionSetRecordHighlight()RecNo=PupilIDEnd FunctionPrivate SubBoxHighlight_Click()SetRecordHighlightEnd SubPrivate SubDetail_Paint()'set border solid (1) for the current record and transparent (0) for all other recordsMe.BoxHighlight.BorderStyle=Abs(Nz(RecNo, 0) =Nz(PupilID, 0))'OR for other border styles, multiply by the appropriate value'2 = dashes, 3 = short dashes, 4 = dots, 5 = sparse dots, 6 = dash dot, 7 = dash dot dot'https://learn.microsoft.com/en-us/office/vba/api/access.rectangle.borderstyle' Me.BoxHighlight.BorderStyle = 6 * Abs(Nz(RecNo, 0) = Nz(PupilID, 0))End Sub