databasedev.co.uk - database solutions and downloads for microsoft access

Microsoft Access Naming Conventions

Naming Conventions - Hungarian Notation:

When programming in Microsoft Access or any other programming language, a common mistake that may occur is when one variable of one type is used as if it is of another variable type.

You may mistake in a line of code when you try to subtract a date value from a string value, which will throw up an error in your code.

What ideally you should do is use one of the common Naming Conventions used, which then allows you to tag, for easy reference and identification, the type of variable that you are using.

In database programming the common naming conventions are either the Hungarian Notation or the Leszynski Naming Convention. The Hungarian Notation is a set of conventions for naming data objects in which a programmer adds a meaningful prefix of one or several characters to the object's name to identify what type of object it is.

The conventions suggest, among other things, that programmers choose prefixes that are suggestive of the type of object named and are easy to remember. Consistency in naming is very important.

Using the Hungarian Notation, especially in Microsoft Access, the programmer would usually choose to add the first three letters of the data type to the beginning of a variables name to distinguish the type of data that the variable contains. Usually, you would then assign the fourth letter of the variable in uppercase, to indicate that this is the actual name of the variable.

The table below demonstrates the usage of this naming convention and gives some examples of it in action:

Data Type Prefix Example Usage
Boolean bln blnActiveAccount
Byte byt bytWeeksInYear
Date dat datDateOfOrder
Double dbl dblPi
Decimal dec decMonthlySalary
Integer int intLengthOfTravel
Long lng lngDistanceOfFlight
Single sng sngNumberOfPages
String str strCompanyName

Whilst it is not compulsory to use a naming convention in Microsoft Access programming, it is advisable to allow others to easily distinguish data types used in your variable naming.