MS-Access / Getting Started

Reserved Words

You probably noticed that there are a number of keywords within VBA that make up the language-for example, For, Next, Do, and Loop. These cannot be used within your program for the purpose of naming variables, subroutines, or functions because they are reserved words. This means they are part of the VBA language itself, and it would cause enormous confusion if you were allowed to go ahead and use these for random purposes within your own code. Fortunately, VBA checks what you are typing in instantly and puts up an error message-usually "Expected Identifier," which means you have used a reserved word and VBA thinks you are entering it as a program statement. Try entering

Dim Loop as String

Loop is, of course, part of VBA and is used in Do loop statements. It is impossible to enter this statement. Instantly an error message appears, and the line of code turns red to warn of a problem. Of course, you can ignore the warning, but as soon as you try to run the code, you will get an error again. Try entering

Sub ReDim()

You will get an error message, and the code will turn red because ReDim is a keyword within VBA.

Strangely enough, you can use words from the Access object model. You can call a subroutine Application or Worksheets, and it will work. Seen problems of code not exiting cleanly when the application is closed down because it used words from the object model. It certainly causes confusion within VBA and should be avoided.

Generally, any VBA keyword or function cannot be used as a variable name, subroutine name, or function name.

[Previous] [Contents]