Subform Highlight
By Richard Rost
11 hours ago
Fix Disappearing Subform Highlight Does the selected row in your Microsoft Access subform lose its highlight when you click somewhere else? In this excerpt from Fitness 78, see why Field Has Focus stops working when you leave the subform, then use an unbound control, the On Current event, and an expression-based conditional formatting rule to keep the current record visible. Watch the full lesson at https://599cd.com/Fitness78 or learn more about conditional formatting in Access Expert Level 19 at https://599cd.com/ACX19.
Related Video: https://youtu.be/ZfQKxXRboPM
Keywords microsoft access subform highlight disappears, access keep selected row highlighted after losing focus, access conditional formatting subform loses focus, access continuous form current record, access on current event
More InformationTranscript All right, let's do, you know what, to make these really stand out, let's make these guys yellow too.
That's only one field in there, so we can just do each one of those individually with a has focus.
So click on this guy, Format, Conditional Formatting, and this will just be Field Has Focus, make it yellow. This way you know exactly which one you're on.
This one too.
All right, Format, Conditional Formatting, Field Has Focus. This will be so much easier to find your way around now.
All right, save it, close it, open it, oh, look at that.
Well, this guy didn't have, oh, that's interesting. Hmm, yeah, you know why? Because you don't have focus when you leave that subform.
Well, we could do the same trick in here even though it's only one field. Let's do it.
I didn't realize, I thought that the focus would stay there even if it was in that subform, but I just learned something new.
So let's do the same thing. This is kind of cramped here, so let's do it outside in the Forms themselves.
So we've got the Program F Design View. We just have to do the same exact thing that we just did before.
So I'll slide this over, so we have some more room here.
Hmm, and we'll copy paste. And we'll set this guy. This will be the current program ID. And that'll be unbound.
And then in the On Current event, we'll say current program ID equals program ID.
And then in the conditional formatting, we will get rid of this. Now we can open this up and change this to Expression Is, program ID equals current program ID.
Hit OK, hit OK, close it, save it, close it, let's take a peek.
All right. And even if I'm over here now, it keeps its yellow.
All right, we'll do the same thing with the routine subform, and then we'll cook them a gas.
So this will be the Routine F Design View. I was looking at it going, wait a minute, but yeah, it's got two boxes in it because it's got the other guy.
All right, so we'll move these over just a little bit. This will be the routine ID.
So it's the current routine ID, copy paste. Slide up.
OK, you are the current routine ID, and get rid of that.
And here we go, Format, Conditional Edit, Expression Is, routine ID equals current routine ID.
Hit OK, OK, save it, close it, and open it, and we forgot our On Current event.
Do I always forget one little step? But see, it's good that I forget them because you'll probably forget them too. I'm just trying to say that to make myself feel better at this point.
Events, On Current.
All right. So the current routine ID equals the routine ID. Now it should work. The buck and pile once in a while.
All right. Ready, and bam. Look at that. So nice. Now you know exactly what program, routine, and routine details are.
Oh, that is sexy. Intro Does the selected row in your Microsoft Access subform lose its highlight when you click somewhere else? In this excerpt from Fitness 78, see why Field Has Focus stops working when you leave the subform, then use an unbound control, the On Current event, and an expression-based conditional formatting rule to keep the current record visible. Watch the full lesson at https://599cd.com/Fitness78 or learn more about conditional formatting in Access Expert Level 19 at https://599cd.com/ACX19.
Related Video: https://youtu.be/ZfQKxXRboPM Quiz Q1. Why might Field Has Focus conditional formatting stop highlighting a control in a subform? A. The control is locked B. Focus moves away from the subform when the user clicks elsewhere C. Conditional formatting only works on main forms D. The form has too many records
Q2. What is the purpose of an unbound control such as CurrentProgramID? A. To store a permanent copy of the program ID in the table B. To display the program description C. To hold the ID of the current record for comparison in conditional formatting D. To automatically create new program records
Q3. Which form event should assign the current record's ID to an unbound control? A. On Click B. On Current C. On Delete D. On Load
Q4. In the Program form, what assignment is used in the On Current event to track the selected program? A. ProgramID = CurrentProgramID B. CurrentProgramID = ProgramID C. CurrentProgramID = RoutineID D. ProgramID = CurrentRoutineID
Q5. What conditional formatting rule is appropriate for keeping the current program highlighted even when focus leaves the subform? A. Field Has Focus B. Record Is New C. Expression Is: ProgramID = CurrentProgramID D. Value Is Greater Than: ProgramID
Q6. Why is Expression Is conditional formatting useful in this situation? A. It highlights controls only while they are being edited B. It compares the record's ID to a stored current ID, regardless of focus C. It permanently changes the background color of the record D. It prevents users from changing records
Q7. What must be repeated for the routine subform to keep its selected routine highlighted? A. Add an unbound CurrentRoutineID control, set it in On Current, and compare it with RoutineID B. Change the RoutineID field to a text field C. Delete the existing conditional formatting rules D. Set the routine subform to read-only
Answers: 1-B; 2-C; 3-B; 4-B; 5-C; 6-B; 7-A
DISCLAIMER: Quiz questions are AI generated. If you find any that are wrong, don't make sense, or aren't related to the video topic at hand, then please post a comment and let me know. Thanks. Summary Today's video from Access Learning Zone continues improving the visual navigation in our program, routine, and routine detail subforms.
I want the active record to stand out more clearly, so I am going to highlight the current record in yellow. For controls that contain only a single field, I can initially use conditional formatting based on whether that field has focus. I set the conditional formatting rule to "Field Has Focus" and choose a yellow background color.
This works well while the cursor remains in that specific control. However, when I move out of a subform and into another part of the main form, the control in the subform no longer technically has focus. As a result, the yellow highlighting disappears even though that record is still the active record in the subform.
To solve this, I use the same technique we used previously for identifying the current record. Rather than relying on focus, I create an unbound control on the subform to store the ID of the current record.
In the Program form's Design View, I add an unbound textbox named CurrentProgramID. In the form's On Current event, I set CurrentProgramID equal to the ProgramID for the current record. This ensures that whenever the user moves to a different program record, the unbound textbox is updated with that program's ID.
Next, I change the conditional formatting rule for the ProgramID control. Instead of using "Field Has Focus," I use an "Expression Is" rule that compares the ProgramID field to CurrentProgramID. When the IDs match, Access applies the yellow formatting.
This means the selected program remains highlighted even when the user moves to a different subform or control elsewhere on the screen. The form continues to show which program record is currently selected.
I repeat the same process for the Routine form. I add an unbound control named CurrentRoutineID, update it in the form's On Current event so it stores the current RoutineID, and then change the conditional formatting rule for the RoutineID control. The formatting expression compares RoutineID with CurrentRoutineID. When those values match, the current routine is highlighted in yellow.
Be sure not to forget the On Current event. The conditional formatting expression depends on the unbound current-ID control being updated whenever the user changes records. If that event is missing, the highlighting will not work correctly.
With these changes in place, the active program, active routine, and active routine detail are much easier to identify. Each selected record remains highlighted even when the user is working in another subform, making the overall form easier to navigate.
You can find a complete video tutorial with step-by-step instructions on everything discussed here on my website at the link below. Live long and prosper, my friends. Topic List Conditional formatting for focused subform fields Using unbound controls to track current record IDs Setting form On Current events to update IDs Highlighting active program and routine records Article Conditional formatting can make a complex form much easier to navigate by clearly showing which record is currently selected. In a form with program, routine, and detail subforms, highlighting the active item in yellow helps users immediately see where they are working.
For a control that remains focused while the user is working in that same form, the simplest approach is to use conditional formatting based on focus. Open the form in Design View, select the control you want to highlight, and open its Conditional Formatting settings. Create a rule for Field Has Focus and choose a yellow fill color. Repeat this for other controls where the focus will remain on the control while the user is editing it.
This works well within a single form, but there is an important limitation with subforms. When the user clicks into another subform, the original control no longer has focus. Its Field Has Focus formatting will turn off, even though its record is still the currently selected record. To keep the selected record highlighted after focus moves elsewhere, use a hidden unbound control to store the ID of the current record.
For example, in a Program form, create an unbound text box named something like CurrentProgramID. It does not need to be visible to the user. Its purpose is simply to hold the ID of the program record that is currently active. In the form's Current event, use code that updates this hidden control whenever the user moves to another program record. The code should take the ProgramID from the current record and place it into CurrentProgramID.
Next, select the visible ProgramID control or whichever control should be highlighted. Open Conditional Formatting and create an Expression Is rule. The expression should compare the record's ProgramID with the hidden CurrentProgramID value. When the two values match, apply a yellow fill color.
This approach makes the selected program remain yellow even after the user clicks into a related routine or detail subform. The highlight is no longer dependent on keyboard focus. Instead, it is based on which record the form recognizes as current.
Use the same pattern for the Routine form. Add a hidden unbound control such as CurrentRoutineID. In the form's Current event, update it with the RoutineID of the current record. Then set a conditional formatting rule on the appropriate visible routine control that compares RoutineID to CurrentRoutineID. When they match, display the yellow highlight.
Make sure the form's Current event is configured. This is the step that updates the hidden value whenever the user navigates to a different record. If the event is missing, the conditional formatting expression has nothing current to compare against, so the highlighting may not update correctly.
After saving and reopening the forms, the selected program, selected routine, and active detail record can each remain visibly highlighted. This makes multi-level forms much clearer because users can see the current selection at every level, even when they are actively entering data somewhere else. Primary Topics
Access form conditional formatting, Field Has Focus formatting, Expression Is conditional formatting, unbound current ID controls, Form On Current event, program and routine subforms Secondary Topics
subform focus behavior, record selection visibility, design view editing
|