Time for a quick Access developer quiz. This one covers a few small but important details that come up constantly when you are working with forms and VBA: event procedures, opening forms at new records, Yes/No controls, and knowing exactly when a text box's After Update event runs. These are the kinds of details that separate a form that behaves nicely from one that seems possessed by the invisible monster.
Try answering each question before reading the answer. If you want to make it a proper quiz, give yourself about three seconds per question. No peeking. Well, minimal peeking.
{{YOUTUBE_EMBED_PLACEHOLDER}}Question 1: Which Access option makes the Code Builder the default choice when you create an event procedure?
A. Compile On Demand
B. Require Variable Declaration
C. Always Use Event Procedures
D. Show Hidden Objects
The answer is C. Always Use Event Procedures. This setting is found in Access Options. When it is enabled, Access assumes you want VBA code when you create an event handler. Otherwise, Access may ask whether you want to use a macro, expression, or code builder every time. If you are writing VBA regularly, that extra question gets old fast.
Question 2: Which DataMode argument opens a form directly at a new blank record with DoCmd.OpenForm?
A. acFormEdit
B. acFormReadOnly
C. acFormAdd
D. acFormDS
The answer is C. acFormAdd. Opening a form with acFormAdd takes the user directly to a new blank record, ready for data entry. This is useful when the purpose of a button is clearly "add a new customer," "create an order," or something similar. There is no reason to make the user open the form, land on an old record, and then hunt for the new-record button.
Question 3: Which event should contain VBA that runs after a user changes a text box value and commits that change?
A. After Update
B. On Click
C. On Current
D. On Open
The answer is A. After Update. The After Update event runs after the value in that particular control has changed and the change has been committed. Usually, that happens when the user leaves the control or otherwise causes Access to save its new value.
This matters because On Click does not tell you that the user changed anything. They might click in a text box, click it again, stare at it thoughtfully, and leave without touching a character. No change occurred. After Update is the event to use when your code depends on a real change to the control's value.
Question 4: For a Yes/No control named ShipSameAsBilling, which VBA condition correctly tests whether it is checked?
A. If ShipSameAsBilling Then
B. If ShipSameAsBilling = "Yes" Then
C. If ShipSameAsBilling Is Text Then
D. If CheckBox(ShipSameAsBilling) Then
The answer is A. If ShipSameAsBilling Then. A Yes/No control already evaluates as True or False, so VBA can use it directly in an If statement. You can write If ShipSameAsBilling = True Then if you really want to, but it is extra typing without adding anything useful. Save those keystrokes for something exciting, like correcting a typo in a field name.
Question 5: Suppose your form copies billing address fields into shipping address fields only while ShipSameAsBilling is checked. The user unchecks that box and later changes the billing city. What should the Billing City After Update code do?
A. Clear the shipping city automatically
B. Leave the shipping city unchanged
C. Copy the billing city anyway, then uncheck the box again
D. Save the record and close the form
The answer is B. Leave the shipping city unchanged. Once the user unchecks Same as Billing, they are telling you that the shipping address is now independent. They may be sending the order to a different office, a customer, a relative, or a secret volcano lair. Your billing-city After Update code should first check whether the box is still checked. Only then should it copy the billing city to the shipping city.
That simple condition prevents a very common form-design mistake: overwriting data the user deliberately customized. The After Update event is powerful because it lets your form respond right after a meaningful edit, but it still needs to respect the user's choices.
If you got all five, congratulations, you have successfully calmed the ancient Access mind machine. If not, watch the embedded video for the quiz walkthrough, and check out Access Developer Level 1, Lesson 6 for more work with the After Update event and form automation.
Live long and prosper,
RR
No comments:
Post a Comment