Time for a little Access quiz. This one covers forms, events, bound controls, and one of those annoying little macro limitations that can catch you off guard when you try to change a toggle button caption from a standalone macro.
Grab a piece of paper, keep score if you like, and see how you do. These are the kinds of details that separate "it mostly works" from a form that behaves properly no matter which record the user is viewing.
Question 1: What happens when two bound controls on the same form use the same Yes/No field as their Control Source?
A. Only the first control can update the field.
B. Each control stores a separate copy of the value.
C. Both controls reflect and edit the same underlying field value.
D. Access automatically converts one control into a label.
The correct answer is C. Both controls are bound to the same field in the form's record source, so they both display and edit the same value. Change one, and the other one reflects that change as Access updates the form.
This is not limited to check boxes or toggle buttons, either. The same idea applies to text boxes, combo boxes, and other bound controls. They are not separate little storage containers. They are simply different windows looking at the same field.
Question 2: Which form event is useful for updating controls whenever the user moves to a different record, including when the form first opens?
A. On Current
B. On Click
C. Before Insert
D. On Close
The answer is On Current. The Current event fires whenever the form moves to a new current record. That includes opening the form, navigating with the record selectors, using search tools, moving through records with code, and so on.
If you need to update a caption, color, visibility setting, enabled state, or another control property based on the current record, Form Current is usually where that logic belongs. It makes sure the form gets refreshed every time the user lands on a different record, not just when they click a particular button.
Question 3: A form's On Current event and a toggle button event must both perform the same sequence of macro actions. What is the best design?
A. Copy the actions into both embedded macros.
B. Put the actions in a standalone macro and use Run Macro from both events.
C. Put the actions in the table's validation rule.
D. Create a separate copy of the form for each event.
The right answer is B. Put the shared actions in a standalone macro, then call that macro from both events using Run Macro.
Copying the same actions into multiple embedded macros works right up until you have to change something. Then you update one copy, forget the other copy, and suddenly your form has developed two competing personalities. Keeping shared logic in one standalone macro is cleaner and easier to maintain.
Question 4: Why can the Set Property macro action fail when a standalone macro tries to change a control on a named form?
A. Set Property can only change captions, not values.
B. Standalone macros cannot work with open forms.
C. Set Property is limited to controls in the form containing the embedded macro.
D. A form control must first be converted to an unbound control.
The correct answer is C. The Set Property macro action is designed to work with controls on the form containing the embedded macro. When you move that logic into a standalone macro, it no longer has that same form context. You cannot just point Set Property at some arbitrary control on an open form and expect it to cooperate. Access has rules, because apparently it enjoys making us earn our coffee.
A standalone macro can absolutely work with open forms. You just need to use the appropriate action for the job.
Question 5: In a standalone macro, which setup correctly assigns the literal caption "Invoice" to a toggle button named StatusToggle on an open form named OrderF?
The correct approach is to use the Set Value macro action.
Set the Item property to Forms!OrderF!StatusToggle.Caption. Then set the Expression property to "Invoice".
The quotation marks matter. Without them, Access assumes Invoice is the name of a field, control, function, or other identifier. With quotation marks, Access knows you want the literal text Invoice assigned to the toggle button's Caption property.
This is the key distinction: Set Property is convenient inside an embedded macro because Access knows which form owns the macro. For a standalone macro that needs to affect a specific open form, use Set Value and fully qualify the target control with the Forms collection, form name, control name, and property name.
So yes, a standalone macro can change a toggle button caption. Just do not try to force Set Property to do a job it was not designed to do. Use Set Value, point it to something like Forms!OrderF!StatusToggle.Caption, and give it the text you want.
If any of these questions tripped you up, watch the embedded video for the full walkthrough and demonstrations. These details are also covered in Access Advanced Level 2, Lesson 3.
Live long and prosper,
RR
No comments:
Post a Comment