Time for a quick Microsoft Access developer quiz. These five questions cover some of the basic VBA concepts you need to understand before you start adding custom programming to your forms and databases. Keep track of your answers, and no peeking at the answers until you've made your picks.
VBA, or Visual Basic for Applications, is what lets you move beyond the built-in features of Access and tell the database exactly what you want it to do. If you are ready, here are five quick questions.
Question 1: In Microsoft Access, what is VBA primarily used for?
A. Automating tasks and adding custom behavior
B. Storing records and tables
C. Formatting printed pages
D. Creating relationships between tables
Answer: A. VBA is primarily used for automating tasks and adding custom behavior. Tables store your data, relationships connect tables, and reports handle printed output. VBA is what you use when you need Access to do something more specific, such as validate data, open forms under certain conditions, calculate values, respond to a button click, or run a sequence of actions automatically.
Question 2: Which Access event would normally be used to run VBA when the user presses a command button?
A. On Click
B. On Current
C. On Open
D. On Delete
Answer: A. The On Click event is normally used for a command button. A button exists to be clicked. Nice and logical for once.
The On Current event runs when the current record changes, On Open runs when a form or report opens, and On Delete is related to deleting a record. If the user clicks a button and you want VBA to run, start with the button's On Click event.
Question 3: What does the VBA message box command do?
A. Display a message dialog box
B. Save the current record
C. Open the table in Datasheet View
D. Send a message to another Access user
Answer: A. A VBA message box displays a message dialog box. You can use it to notify the user, ask a yes-or-no question, show an error message, or simply confirm that your code got to a particular point while you are testing it.
A message box is one of the first VBA tools most developers learn because it is simple, useful, and hard to misunderstand. If you tell Access to display a message box, it displays a message box. Technology at its finest.
Question 4: In VBA, what is the main difference between a sub-procedure and a function procedure?
A. A function can return a value, and a sub does not
B. A sub can use variables, and a function cannot
C. A function only works in queries
D. A sub only works in forms
E. A sub must be public, and a function must be private
Answer: A. A function can return a value, while a sub-procedure does not directly return a value. Use a sub when you want VBA to perform an action, such as opening a form or changing a control's value. Use a function when you want VBA to calculate something and give you a result back.
There are some more advanced wrinkles, such as passing values back through ByRef parameters, but the basic rule is simple: functions return values; subs perform actions.
Question 5: Why should you avoid using a VBA keyword as the name of a variable, field, or control whenever possible?
A. Access may interpret it as a programming command
B. It prevents the object from being saved
C. It automatically changes the data type to text
D. It makes the object visible only in Design View
Answer: A. Access may interpret the name as a programming command. Using reserved words and VBA keywords for your own objects can create confusion and sometimes cause outright errors.
For example, do not name a variable MessageBox. That name is too close to a command Access and VBA may expect to use for something else. Give your fields, controls, and variables clear, descriptive names that do not collide with VBA commands. Your future self will appreciate it, especially when you are debugging something at 2:00 AM and wondering why Access has suddenly developed a personal grudge against you.
How did you do? If you got all five correct, you have a solid grasp of these Developer Level 1 basics. If you missed a couple, no worries. VBA takes practice, and these are exactly the kinds of foundational concepts that become second nature once you start using them in real databases.
Watch the embedded video for the full quiz walkthrough. These topics, along with plenty more practical VBA lessons, are covered in my Microsoft Access Developer Level 1 class.
Live long and prosper,
RR
No comments:
Post a Comment