This appendix gives you suggestions for naming variables and other database objects. The suggested standards are based on the Reddick VBA Naming Conventions (RVBA).
When creating variable names, it’s important to make the type and intended use of each variable clear and self-documenting. Here are a few rules to follow:
Remember to always make variable names mixed case, with each word or abbreviation in the variable name capitalized.
Don’t use underscore characters in your variable names.
Abbreviate variable names only when it’s necessary.
Make the beginning of each variable name describe the type of data it contains.
Following these conventions will go a long way toward keeping your code concise and readable. The format for an object is
[prefixes]tag[BaseName[Suffixes]]
A prefix
appears in lowercase and is used to indicate additional information, such as the scope of a variable. The tag
also appears in lowercase. It is a short set of characters that indicates the type of an object. Use the BaseName
to indicate what the object represents. Capitalize the first letter of each word in the BaseName
. Suffixes
, when used, provide additional information about the meaning of the BaseName
. An example of a name for an object is
mstrFirstName
Use the prefix m
to indicate that the variable appears at the module level. The tag str
indicates that the variable contains a string. The BaseName FirstName
indicates that the variable holds a first name. Table B.1 recommends prefixes for Access object tags.
Table B.1. Recommended Prefixes for Access Object Tags
Prefix | Control Type | Example |
---|---|---|
|
| Application |
| CheckBox |
|
| ComboBox |
|
| CommandButton |
|
| Control |
|
| Controls |
|
| CustomControl |
|
|
|
|
| DoCmd |
|
|
|
|
|
|
|
| Form |
|
| Forms |
|
|
|
|
| Image |
|
| Label |
|
| Line |
|
| ListBox |
|
| Module |
|
| ObjectFrame |
|
| OptionButton |
|
| OptionGroup (frame) |
|
| PageBreak |
|
| PaletteButton |
|
| Properties |
|
| Rectangle |
|
|
|
|
|
|
|
| Report |
|
| Reports |
|
| Screen |
|
| Section |
|
| Subform |
|
| SubReport |
|
|
|
|
| TextBox |
|
| ToggleButton |
|
Table B.2 lists prefix tags for standard variable types, as well as the storage space required by each.
Table B.2. Standard Variable Data Type Tags
Data Type | Storage | Example | |
---|---|---|---|
| Byte | 1 Byte |
|
| Boolean | 2 bytes |
|
| Integer | 2 bytes |
|
| Long | 4 bytes |
|
| Single | 4 bytes |
|
| Double | 8 bytes |
|
| Currency | 8 bytes |
|
| Date and Time | 8 bytes |
|
| Object | Varies |
|
| String | 1 byte per character |
|
| String (fixed length) | 10 bytes + 1 byte per char |
|
| Variant | 16 bytes + 1 byte per char |
|
Access 2002 provides the ActiveX Data Objects Library. Table B.3 lists the recommend tags for ADO.
The Jet Engine uses objects you might need to refer to in VBA code. Table B.4 lists the Data Access Objects (DAO) object types and their standard naming prefixes.
Table B.4. Jet Object/Collection Prefixes
Prefix | Object Type |
---|---|
| Container |
| Containers |
| Database |
| Databases |
| DBEngine |
| Document |
| Documents |
| Error |
| Errors |
| Field |
| Fields |
| Group |
| Groups |
| Index |
| Indexes |
| Parameter |
| Parameters |
| PrivDBEngine |
| Property |
| Properties |
| QueryDef |
| QueryDefs |
| Recordset |
| Recordsets |
| Relation |
| Relations |
| TableDef |
| TableDefs |
| User |
| Users |
| Workspace |
| Workspaces |
In addition to the standard notations for variables, there are variable notations for scope and lifetime. These should be placed at the beginning of the variable, before any other prefix. Table B.5 lists the scope and lifetime prefixes.
Table B.6 lists general naming convention tags for the Database window objects.
There are two sets of naming conventions you can use when naming specific database window objects: Either use the prefix for the general object prefix from the table, or supply one of the more descriptive tags listed in Table B.7.
Table B.7. Tags for Specific Database Window Objects
Suffix | Object Type | |
---|---|---|
| Lookup | Table (lookup) |
| (none) | Query (select) |
| Append | Query (append) |
| XTab | Query (crosstab) |
| DDL | Query (DDL) |
| Delete | Query (delete) |
| Filter | Query (filter) |
| Lookup | Query (lookup) |
| MakeTable | Query (make table) |
| PassThru | Query (SQL pass-through) |
| Totals | Query (totals) |
| Union | Query (union) |
| Update | Query (update) |
| Dlg | Form (dialog) |
| Mnu | Form (menu) |
| Msg | Form (message) |
| Subform | Form (subform) |
| SubReport | Form (subreport) |
| Mnu | Macro (menu) |
3.15.31.206