Microsoft access: the mindset of the vba programmer

Author: Ben Beitler
Microsoft Access Database : The mindset of the VBA programmer

From my new VBA book due out soon, here’s an extract about the mindset of the Microsoft Access database VBA programmer…

We need to start by establishing a frame of reference as to what we should expect when we are writing VBA code.

Consider the scenario where you command a child to "open the door." Think about all the individual actions that it takes to accomplish that one statement. The child has to approach the door, align the hand with the door knob, move the hand and grasp it around the door knob, and then twist and pull the door knob while swinging the arm in an arc motion.

We don’t have to command each specific step, and indeed life would be very tedious if we constantly had to issue commands at such a micro level of detail. However, somewhere along the line, the child had to learn what it meant and all the steps in the process to open a door. The child didn’t have to be told for each step and probably figured it out by observing others and by bumping into themselves a few times.

When working on a computer, it is helpful to remember that computers have to be instructed, basically shown the way on how you want it to do things. Be clear, the first thing to remember about computers is that they can’t do what you didn’t tell them to do.

Therefore, to ask the computer to open the door is meaningless until you actually define the exact steps required to accomplish the task. You can’t rely on the computer to observe and understand the act of opening the door as a child would. Fortunately, you can build upon the work done by other programmers. So, for example, when you want to display a little message box saying, "Hello, World!" you can use a single line of code or instructions as shown below. This combines programming done by others with something you want said.

MsgBox "Hello, World!"

Behind the scenes, the instruction (command) MsgBox goes through several steps; it instructs the computer how to draw the box, how to position it, what button to put on it, and how to style it.

All of those details are abstracted away from us, which makes our task so much easier. Knowing that the computer needs every step to be defined, you can appreciate the benefit of being able to leverage existing programming and commands to write your own code. But it’s still upon you to supply the missing pieces, like the actual message "Hello, World!" Remembering the general rule that it can’t do what you didn’t tell it to do is invaluable in programming.

When writing code, you are working with a type of program called a compiler, which is responsible for translating the VBA language into machine language that the computer can understand and execute. As you write code, the compiler provides feedback on whether statements are valid and free of syntax errors (structural errors). When discussing how the computer will react, we will often refer to the compiler or VBA Editor.

Keep an eye out for the release of my new book: Microsoft Access VBA Programming soon