Blog Home  Home Feed your aggregator (RSS 2.0)  
Doctor Access Blog - Do You Use Any Naming Convention for Controls in MS Access? If No, Why Not?
Everything About MS Access
# Wednesday, October 05, 2011

Ok, so I have asked the questions, but now I am thinking that perhaps the better question might be, do you even provide any custom naming for any controls?

Forms and reports are an inevitable part of any good database application. Forms provide the platform for users of the application to interact with the data. Reports provide the ability to present the data in a predefined and structured manner. Both forms and reports required controls to display data.

For the purpose of this writing, I will concentrate my thoughts on Forms. We will leave the discussion of controls in reports to another time.

During development of the database application adding controls to forms is a very common and required practice. These controls can be added to forms and/or reports in a variety of ways. Users can use a wizard to add a form and have the required controls added by the wizard. Users can also simply select a table and click the “Fom” option from the “Create” tab on the ribbon and Access will automatically create a form that will allow the user to interact with the data in the table. Alternately user can also simply create a completely blank form, provide a record source for the form and then user one method or the other to add the required controls to the blank form.

Forms come in basically two varieties, bound and unbound. This subject is one that must be address by its self. Here is a link that will help to understand this concept better:

Every control that is added to a form or report must have a name. No matter what method is used to add controls to a form, Access does the best job possible to provide names for all controls by naming the using the name associated with the type of control and then adding an incrementing number to the end of that name.

I consistently see VBA code from others where they are attempting to refer to controls that clearly have the default names provided by Access when the control was added. As a result, I have come to believe that many Access developers do not understand that they should use some type of naming convention to provide meaningful names for the controls on their forms.

While I have no desire to try to tell anyone what naming convention to use, I do want to strongly encourage all Access developers to adopt and use some naming convention. You might not want to adopt any one specific naming convention but rather take the options offered by other naming conventions and develop your own custom naming conventions. So, here are some links that might just inspire some of you to actually start using some sort of naming convention. So check out these links: The Leszynski Naming Convention, The Lexzynski/Reddick Naming Convention or the Microsoft Access Object Naming Conventions.

What should be named and what might not need to be named? During the development of my own forms, the only controls that I do not individually name are labels that are associated with or attached to other controls. In the event that I plan to manipulate a label associated with another control is associated with or attached to another control, I will also provide a custom name for the label as well as the primary control. One condition where I do this is when I have a check box that has a Yes/No field as its data source. Let’s say the check box has a Yes/No field named “Active”. I would name the check box “chkActive”. I would also provide a name for the that is associated with or attached to that check box. I would name the label “lblStatus”. This way I can refer to each control independently but still have the label to be connected to the check box so when I hide the check box, the connected label is also hidden.

I cannot begin to tell you how critical it is during the VBA coding process to have your controls named with meaningful names. Only when you have experienced this will you be able to understand the positive impact that using a good, consistent naming convention will have on your coding ability.

I will be posting more on creating, naming and using objects in Access in future posts.

I invite your comments on this and any other subject on my blog.

Wednesday, October 05, 2011 3:47:54 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0]    |  Trackback
Copyright © 2020 AppliTech, Inc.. All rights reserved.
DasBlog 'Portal' theme by Johnny Hughes.
Pick a theme: