Naming Conventions

What is a Naming Convention?

A Naming Convention is simply a standard rule (could be through the use of prefixes, suffixes, typographical convention (syntax styling) such as CamelCase, …) that you apply when creating names for :

  • Objects
    • Tables
    • Queries
    • Forms
    • Reports
    • Macros
    • Modules (See VBA Components)
  • Table Fields
  • Controls (Forms & Reports)
  • VBA Components (Modules, Class Modules) & Variables…
Not Just An Access Thing
This is true in any programming language and not just an Access, MS Office or VBA thing.

Why Use a Naming Convention?

Simple, to standardize your work and make it easier to follow.

For instance, take a simple example of

Public Sub Demo()
    For cars = 0 To 10
        Accident = DateAdd("d", cars, Date)
        Debug.Print Accident
    Next cars
End Sub

what is Accident and cars?  Strings, Integer, Long, …?

Now, if you implement a basic naming convention and prefix all your VBA date variables with dt for Dates and i for Interger numbers you get

Public Sub Demo()
    For icars = 0 To 10
        dtAccident = DateAdd("d", icars, Date)
        Debug.Print dtAccident
    Next icars
End Sub

and the code becomes much more legible.  You don’t even need to look at the procedure’s variable declarations to understand that dtAccident is a Date and icars is a Integer number.

So by using naming conventions you

  • Standardize your work
  • Simplify reading your code (imagine long procedures where you need to scroll up and down to see variable declarations, by using a naming convention, you no longer need to look at the declaration to know exactly what type of variable you are working with)
  • Simplify troubleshooting
  • Aid in finding things when they are listed together (imaging a list of database Objects with object prefixes, it becomes very easy to distinguish forms from reports and tables form queries, …)
Do Not Forget
Some of what you do today is not so much for the immediate benefit, but rather to facilitate your life when you need to revisit your code in a month’s time, in a year’s time, … You may understand today that cars is an integer, but I can guarantee you won’t in a year from now. By using a Notation, it won’t make any difference, you’ll be able to peruse your code and instantaneously start working.

What are Some of the Existing Naming Conventions?

If you Google the subject of Naming Conventions you will be inundated with all sorts of conventions.  In Access, or VBA in general, you will commonly hear of the following ones:

You’ll notice that Hungarian, RVBA and Leszynski are all very similar as they are derivative of the Hungarian.

Let’s Not Get Hung Up on Specifics!

Now, I know some people will be sticklers for one notation or another, but the truth of the matter is that it truly doesn’t make any difference whatsoever!  The name of the game here is consistency!

What is important is that you have some standard and you stick with it throughout any given project.

  • You can use your own notation.  There’s nothing wrong with that.
  • You can change notations from project to project (just don’t change notations within a single project).  Once you start with one, stick with it, or if you decide to change notations, update it throughout your project.

More resources on the subject

One response on “Naming Conventions

  1. David Holladay

    I agree 100% that naming protocols are indispensable. Within my first year of programming in VBA, way long ago, I had the unpleasant experience of MYPS (Meeting My Past Self) in code. I could not figure out what I’d written, what it did, why I wrote…embarrassing it was.
    The important thing is to have one (a naming protocol) and, come hell or high water, stick to it. You will realized huge savings in time, embarrassment, frustration plus your code becomes ever-so-much-more reusable…