0% found this document useful (0 votes)
50 views4 pages

Reddick VBA Naming Conventions

The document provides naming conventions for variables and objects in VBA. It recommends using mixed case with initial capitalization for each word, avoiding underscores, and including a prefix to indicate the type of data or object. Standard prefixes are provided for variables of different data types, objects in collections, scope/lifetime, and database objects like tables and queries. Specific suffixes further identify query and form types. Following these conventions helps make code more readable and maintainable.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views4 pages

Reddick VBA Naming Conventions

The document provides naming conventions for variables and objects in VBA. It recommends using mixed case with initial capitalization for each word, avoiding underscores, and including a prefix to indicate the type of data or object. Standard prefixes are provided for variables of different data types, objects in collections, scope/lifetime, and database objects like tables and queries. Specific suffixes further identify query and form types. Following these conventions helps make code more readable and maintainable.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Reddick VBA Naming Conventions (RBVA)

When creating variable names, it’s important for you 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 The BaseName is used to indicate what the object represents. The first letter of each word in the
BaseName is capitalized. Suffixes, when used, provide additional information about the meaning of the
BaseName. An example of a name for an object is

mstrFirstName

The Prefix m is used to indicate that the variable appears at the module level. The tag str is used to
indicate that the variable contains a string. The BaseName FirstName indicates that the variable holds a
first name.

Object Naming Conventions


Prefix Control Type Example
app Application appInfoBase
chk CheckBox chkReadOnly
cbo ComboBox cboLanguages
cmd CommandButton cmdRefreshTable
ctl Control ctlAny
ctls Controls ctlsAll
ocx CustomControl ocxCalendar
dcm DoCmd dcmOpenForm
frm Form frmDataEntryView
frms Forms frmsClientsAndOrders
img Image imgLongShot
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
rpt Report rptOrders
Object Naming Conventions – Continued..
Prefix Control Type Example
rpts Reports rptsTodaysChanges
scr Screen scrSecondSplashScreen
sec Section secOrderDetail
fsub SubForm fsubBillableHours
rsub SubReport rsubTopFiveSales
txt TextBox txtAdditionalNotes
tgl ToggleButton tglShowFormatting

Standard Variable Data Type Tags


Prefix Data Type Storage Example
byte or byt 1 byte byteArray
bool or f Boolean 2 bytes boolSecurityClear
boo Boolean (modified) booSecurityClear
bit Boolean (for MySQL) bitIsRoot
blob
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 8 bytes datBirth
dtm Date and Time 8 bytes dtmStartTime
obj Object varies objActiveObject
str String 1 byte per strFirstName
character
stf String 10 bytes stfSocNumber
(fixed length) + 1 byte per char
var Variant 16 bytes varInput
+ 1 byte per char
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.

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
Tags For Database Window Objects
Prefix Object Type
tbl Table
qry Query
frm Form
rpt Report
mcr Macro
bas Module

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)

You might also like