Thou Shalt Not Use VBA Statements in Vain

Or, to put this another way, thou shalt not attempt to make up thine own programming language.

You need to know the exact spelling and syntax of every VBA keyword and every Access object that you name. If the correct line to type is

DoCmd.OpenForm "myForm", acNormal, , , acFormEdit don't assume that something reasonably close, like any of these examples, will work:

Do Cmd.OpenForm

"myForm"

acNormal,

, , acFormEdit

DoCmd.Open Form

"myForm"

acNormal..

acFormEdit

DoCmd.OpenForm

myForm",

acNormal, ,

, acFrmEdit

DoCmd.Open Form

"myForm"

acNormal,

, , acFormEdit

DoComnd.OpenForm "myForm

, acNormal,

, , acFormEdit

DoCmd.OpenForm

myForm",

"acNormal",

, , "acFormEdit

After casual observation, you might think that any of these six lines would work in place of the original example. In fact, each of these six statements contains a syntax error (additional spaces, misspelled words, missing commas, and so forth) that would cause the line to fail.

III. Remember to Keep Holy the VBA Syntax

Every VBA statement has strict rules of syntax that define the exact spelling, punctuation, and order of items in that statement. They're not suggestions: They're rules that must be obeyed if you expect your code to work. (Okay, so we're still harping on the second commandment.)

If you don't have a clue what that shaded box in Figure 15-1 is about, or why FormName is in boldface there, study in earnest how to understand syntax in Chapter 3. Woe be to those who don't heed this warning, for surely they will live their remaining programming days breaking the tenth commandment.

Figure 15-1:

Don't be clueless.

Figure 15-1:

Don't be clueless.

Was this article helpful?

0 0

Post a comment