|
|
Option Explicit
Option Explicit is a compiler directive. Using Option Explicit enables the compiler to catch misspellings so users do not have as many surprises at run-time. It is always a good idea to DIMension your variables before you use them -- and best to be a specific data type if it applies and you do not need to store a null (as only a variant can do) Dim nPartID As Long to force variable declaration (which is HIGHLY recommended), put this at the top of your module: Option Explicit from the VBE window, you can do --> Tools, Options... and check "Require Variable Declaration" so that any new modules created will have the Option Explicit statement automatically at the top. Modules that have already been created will not be changed. Another handy thing in declaring variables is that, if Access recognizes the variable name you have typed as a variable that has been DIMensioned, it will change the case for you after you move off the line -- so it is good to put one or more uppercase characters in variable names and type everything in lower case npartid --> will be corrected to --> nPartID If you declare a variable but do not specify its type, Access will assume it is a variant -- this takes extra space. Declared variable access is slightly faster than undeclared variable access. When you use a Variant type, which can hold any type of data -- numbers, strings, arrays, etc – you have flexibility to be lazy, and that also degrades performance. In order to work with a Variant, Access has to figure out what type of data it has, keep track of that in another place, as well as perform conversions, whereas if you specify a data type, Visual Basic can compile the code more efficiently. Another reason to specifically declare the data type is so that the AutoComplete feature of Visual Basic can list only things that apply specifically to that data type. other compiler directives: Option Compare Database
This statement sets the default lower limit index of an array to 1 instead of the default of 0 (zero). There are more compiler directives, but these are the most common. MODULE INFORMATION this thread has some good reference information: Code Behind Form (CBF)
|
| This page was last modified 17:03, 11 February 2012. This page has been accessed 2,469 times. Disclaimers |