This appendix gives you suggestions for naming variables and other database objects. The suggested standards are based on the Reddick VBA Naming Conventions (RVBA), which are commonly accepted in the industry.
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
tag also appears in lowercase. It is a short set of characters
BaseName to indicate what the object
BaseName. Suffixes , when used,
BaseName . An example of a name for
mstrFirstName
Use the prefix m to indicate that the variable appears at the module level. The tag str
BaseName FirstName indicates that the
Prefix | Control Type | Example |
---|---|---|
Application | appInfoBase | |
CheckBox | chkReadOnly | |
ComboBox | cboLanguages | |
CommandButton | cmdRefreshTable | |
Control | ctlAny | |
Controls | ctlsAll | |
CustomControl | ocxCalendar | |
dap | DataAccessPage | dapCustomers |
DoCmd | dcmOpenForm | |
fcd | FormatCondition | fcdOverDue |
fcds | FormatConditions | fcdsRules |
Form | frmDataEntryView | |
Forms | frmsClientsAndOrders | |
hyp | Hyperlink | hypCustomers |
Image | imgHeadShot | |
Label | lblShowAllCheckBox | |
Line | linDivider | |
ListBox | lstLastTenSites | |
Module | basErrorControl | |
ObjectFrame | oleWorksheet | |
OptionButton | optReadOnly | |
OptionGroup (frame) | fraColorSchemes | |
PageBreak | brkTopOfForm | |
PaletteButton | palBackgroundColor | |
Properties | prpsActiveForm | |
Rectangle | shpHidableFrame | |
ref | Reference | refExcel |
refs | References | refsApps |
Report | rptOrders | |
Reports | rptsTodaysChanges | |
Screen | scrSecondSplashScreen | |
Section | secOrderDetail | |
Subform | fsubBillableHours | |
SubReport | rsubTopFiveSales | |
tab | TabControl | tabCustomer |
TextBox | txtAdditionalNotes | |
ToggleButton | tglShowFormatting |
Table B.2 lists prefix tags for standard variable types, as well as the storage space required by each.
Prefix | Data Type | Storage | Example |
---|---|---|---|
Byte | 1 Byte | byteArray | |
Boolean | 2 bytes | boolSecurityClear | |
Integer | 2 bytes | intLoop | |
Long | 4 bytes | lngEnv | |
Single | 4 bytes | sngValue | |
Double | 8 bytes | dblValue | |
Currency | 8 bytes | curCostPerUnit | |
Date and Time | 8 bytes | datStartTime | |
Object | Varies | objActiveObject | |
String | 1 byte per character | strFirstName | |
String (fixed length) | 10 bytes + 1 byte per char | stfSocNumber | |
Variant | 16 bytes + 1 byte per char | varInput |
Access 2003 provides the ActiveX Data Objects (ADO) Library. Table B.3 lists the recommend tags for ADO.
Prefix | Object Type |
---|---|
Command | |
Connection | |
Error | |
Errors | |
Field | |
Fields | |
Parameter | |
Parameters | |
Property | |
Properties | |
rst | Recordset |
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.
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 | |
tbls (or tdfs) | TableDefs |
User | |
usrs | Users |
Workspace | |
wrks | 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.
Prefix | Description |
---|---|
(None) | Local variable, procedure-level lifetime |
Local variable, program-level lifetime (static variable) | |
Private (module) variable, program-level lifetime | |
Public (global) variable, program-level lifetime |
Table B.6 lists general naming convention tags for the Database window objects.
Prefix | Object Type |
---|---|
Table | |
Query | |
Form | |
Report | |
Macro | |
dap | DataAccessPage |
Module |
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.
Prefix | 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 |