Tips and Tricks

Combo Boxes that Allow New Values to be Added

An age old question. How can we use a combo box to add new values to its list, “on-the-fly”?

This question has been answered thousands of times, and people keep asking it. Well, I am adding my voice to the side of the answers crowd in the hopes that at least 1 person will not have to ask.

To read my version of the answer, visit Not-in-List.

p.s. This one comes with a sample database!

Option Explicit

Just a friendly reminder. You need to ALWAYS use Option Explicit. Look at the top of any module of code, whether under forms or modules. The first two lines should be …

Option Compare Database
Option Explicit

By default, Access only puts the 1st one. You have two ways of getting the 2nd line in there.

  1. type it in manually, or,
  2. under Tools, Options in the VBA editor, turn on “Require Variable Declaration”

What does it do? Forces the “compiler” to make sure that EVERY variable has been declared. Basically, helps stop typos from causing “bugs”.

Just trust me on this one, and do it!

Linked Tables Utility

I may have given this one before, but it is SO useful. I personally had to use it last week.

The computer you are at does not have the Linked Tables utility working and you need to know where the user’s data is stored. Try this command in the VBA Editor’s Immediate Window (Ctrl-G)

? CurrentDb.TableDefs(“Holders”).Connect

Where Holders is an example table name (change that to one from your database).

(NOTE: you may have to have DAO references on. see this page if you do not know what that means)