Appendix B. Naming Conventions

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:

  1. Remember to always make variable names mixed case, with each word or abbreviation in the variable name capitalized.

  2. Don’t use underscore characters in your variable names.

  3. Abbreviate variable names only when it’s necessary.

  4. 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

app

appInfoBase

Application

chk

CheckBox

chkReadOnly

cbo

ComboBox

cboLanguages

cmd

CommandButton

cmdRefreshTable

ctl

Control

ctlAny

ctls

Controls

ctlsAll

ocx

CustomControl

ocxCalendar

dap

DataAccessPage

dapCustomers

dcm

DoCmd

dcmOpenForm

fcd

FormatCondition

fcdOverDue

fcds

FormatConditions

fcdsRules

frm

Form

frmDataEntryView

frms

Forms

frmsClientsAndOrders

hyp

Hyperlink

hypCustomers

img

Image

imgHeadShot

lbl

Label

lblShowAllCheckBox

lin

Line

linDivider

lst

ListBox

lstLastTenSites

bas

Module

basErrorControl

ole

ObjectFrame

oleWorksheet

opt

OptionButton

optReadOnly

fra

OptionGroup (frame)

fraColorSchemes

brk

PageBreak

brkTopOfForm

pal

PaletteButton

palBackgroundColor

prps

Properties

prpsActiveForm

shp

Rectangle

shpHidableFrame

ref

Reference

refExcel

refs

References

refsApps

rpt

Report

rptOrders

rpts

Reports

rptsTodaysChanges

scr

Screen

scrSecondSplashScreen

sec

Section

secOrderDetail

fsub

Subform

fsubBillableHours

rsub

SubReport

rsubTopFiveSales

tab

TabControl

tabCustomer

txt

TextBox

txtAdditionalNotes

tgl

ToggleButton

tglShowFormatting

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

Prefix

Data Type

Storage

Example

byte or byt

Byte

1 Byte

byteArray

bool or f

Boolean

2 bytes

boolSecurityClear

int

Integer

2 bytes

intLoop

lng

Long

4 bytes

lngEnv

sng

Single

4 bytes

sngValue

dbl

Double

8 bytes

dblValue

cur

Currency

8 bytes

curCostPerUnit

dat

Date and Time

8 bytes

datStartTime

obj

Object

Varies

objActiveObject

str

String

1 byte per character

strFirstName

stf

String (fixed length)

10 bytes + 1 byte per char

stfSocNumber

var

Variant

16 bytes + 1 byte per char

varInput

Access 2002 provides the ActiveX Data Objects Library. Table B.3 lists the recommend tags for ADO.

Table B.3. Recommended ADO Tags

Prefix

Object Type

cmn or cmd

Command

cnn or cnx

Connection

err

Error

errs

Errors

fld

Field

flds

Fields

prm

Parameter

prms

Parameters

prp

Property

prps

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.

Table B.4. Jet Object/Collection Prefixes

Prefix

Object Type

cnt

Container

cnts

Containers

db

Database

dbs

Databases

dbe

DBEngine

doc

Document

docs

Documents

err

Error

errs

Errors

fld

Field

flds

Fields

grp

Group

grps

Groups

idx

Index

idxs

Indexes

prm

Parameter

prms

Parameters

pdbe

PrivDBEngine

prp

Property

prps

Properties

qry (or qdf)

QueryDef

qrys (or qdfs)

QueryDefs

rst

Recordset

rsts

Recordsets

rel

Relation

rels

Relations

tbl (or tdf)

TableDef

tbls (or tdfs)

TableDefs

usr

User

usrs

Users

wrk

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.

Table B.5. Prefixes for Scope and Lifetime

Prefix

Description

(None)

Local variable, procedure-level lifetime

s

Local variable, program-level lifetime (static variable)

m

Private (module) variable, program-level lifetime

g

Public (global) variable, program-level lifetime

Table B.6 lists general naming convention tags for the Database window objects.

Table B.6. Tags for Database Window Objects

Prefix

Object Type

tbl

Table

qry

Query

frm

Form

rpt

Report

mcr

Macro

dap

DataAccessPage

bas

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.

Table B.7. Tags for Specific Database Window Objects

Prefix

Suffix

Object Type

tlkp

Lookup

Table (lookup)

qsel

(none)

Query (select)

qapp

Append

Query (append)

qxtb

XTab

Query (crosstab)

qddl

DDL

Query (DDL)

qdel

Delete

Query (delete)

qflt

Filter

Query (filter)

qlkp

Lookup

Query (lookup)

qmak

MakeTable

Query (make table)

qspt

PassThru

Query (SQL pass-through)

qtot

Totals

Query (totals)

quni

Union

Query (union)

qupd

Update

Query (update)

fdlg

Dlg

Form (dialog)

fmnu

Mnu

Form (menu)

fmsg

Msg

Form (message)

fsfr

Subform

Form (subform)

rsrp

SubReport

Form (subreport)

mmnu

Mnu

Macro (menu)

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.31.206