References 101
What are they and where are they?
First a little background. Many of the functions,types, objects and commands you use in VBA come from the VBA library. It is in this library that the code exists to manipulate the values you supply and return the answers or actions you expect. For example the Date property returns the current machine date.

Just out of interest...The Date can be set using
Date = "05/03/02"
and it will change the machines date,

Access seeds three library references to get up and running.
1) Access
2) VBA
3) DAO or ADO
Each of these libraries supply or export a variety of functions, objects etc. For instance the Access library exports DoCmd and DLookup, DAO or ADO exports Database and Recordset data types (objects) to name a few of dozens.

Where are these libraries?
The libraries are files on the hard disk. Usually dll files but may have other extensions like .olb or .tlb. An example is 'C:\Program Files\Common Files\Microsoft Shared\DAO\dao360.dll'. They can also be comprised of multiple files.

Why have all these separate libraries and files?
By using separating an functionality into libraries it is possible to create a single library and let multiple applications use it. For example: Excel, Outlook and Word all use the VBA library. This allows you to use the same ‘language’ to program these different applications. If there is a problem with the library then the vendor can distribute the fixed library without having to distribute the whole application again.
In fact the complete set of VBA libraries, including the IDE (code window) can be licensed from Microsoft. The VBA SDK allow you add VBA programmability to any application you may write. ( although the license may seriously max out your Visa card).

So what has all this to do with references?

The idea behind the references collection is to have a place to store a list of the ‘type’ libraries that your application will use. When you first create a blank database, Access creates a reference collection that includes the three libraries mentioned above.
As you gain experience with Access you may want to use other libraries to enhance your application. The Office library will let you manipulate tool bars or that little ‘Clippy’ we all love, or perhaps you want to use the SQLDMO library to manipulate a SQL Server database, or even the Excel library to ‘steal’ some of the nice functions available from it.
The most efficient way to use these libraries is to set a reference to them. When access accepts the reference it stores information about the library in your database.
There is another benefit to giving Access this list. Type libraries don’t only contain code, they also contain the datatypes, argument lists and names of the variables, functions etc. All the descriptive information you see in the object browser comes from the type library. With this list, Access can instruct VBA to compile your code, checking with the type library that you have used the objects and functions correctly, into an efficient stream of PCode because It knows what libraries are used and how best to call them in advance. (This is called early binding). You can reference many libraries from a variety of sources. Third party controls (ocx files) have type libraries built in (usually). When you add a third party control to a form Access automatically adds the reference to the list

Broken references.
What happens if I accidentally delete a dll file that is a reference?
This is where it gets annoying. If this happens and you open your database there is a good chance that the code will stop somewhere with the message ‘Can’t find project or library’. It unfortunately usually stops and points to Date or some other function / command that has nothing to do with the missing library. (At least you know something is wrong) What you must then do is open the references from a code window. It’s usually under the tools menu.

Notice the missing reference! (5th down)
By high-lighting the reference with the mouse you can see where the library file is. Now comes the fun part. This broken reference could result from the file being missing. So go to the location shown and see if its there. If not..well where the bleep did it go! You will have to search around the hard drive to see if you can find it or re-install the library (or post on Microsoft.public.access.forms group). But there is another evil that can befall your library. It is not hard to imagine that another application installed recently also uses this library. But it actually uses an older version that doesn't support the stuff that your version did. Thus all the precompiled code magic is wasted because some of the functions required and optimised by your application are not in the new library. VBA immediately decompiles your code as it knows something is very wrong because it loads and checks the libraries prior to running your code / application. This scenario can be quite a problem as the path shown on the reference window will point to the new library location. Your only hope here is to search your hard drive using 'Find files or folders' for the file and see if the original is elsewhere. If you find multiple files, look at the dates and sizes. The culprit may be dated earlier. By selecting the file in the search window and pressing [alt]+[enter] the properties box will come up. Here you can see the version number.

If my original version is still on the drive, how come the other version is being used?

Type libraries are registered in the operating system registry. One of the entries is the location (path) to the 'current' version of the file. Installation software (bad ones) will not check versions and put its version somewhere on the hard drive and register the new library as the current in the registry.
It is not unknown for bad installation software to actually replace the later version with an old one and thus your original is gone!

Can I re-point the registry to the version that works.
Yes. You will notice on the tools menu another option call ActiveX controls. Press the Register button. This will allow you to browse the drive, find your library and re-register it. You may have to change the extension selector in the browse box to the type you need. i.e.: from *.ocx to *.dll or *..tlb. Amazing it's so handy to the references menu <g> You can also re-register your library by using the 'Run' button on the start button menu in Windows. Type 'regsvr32 c:\1\burner.ocx' (without the quotes and using the name and path of your library)

Sometimes after registering the library again, you must un-tick the box, hop out of references and then hop back in again, find and re-tick it.
Recompile your code - hopefully you're back in business


For further information on this article contact
peter walker
Other information relevant to this topic is DLL Hell