Monday, May 23, 2005

Resolving References in MS Access Revisited

More on the issue of referencing library databases in Access.

Access will try to update a reference if it cannot find the referenced database in its original location. If the RefLibPaths registry key does not exist or does not contain a proper reference, Access uses the SearchPath API to search for the referenced file.

The following searches are performed in the order indicated:



So for all versions of Access the most reliable approach is to locate the library file in same directory as the MSACCESS.EXE file. You can add additional directory paths to the hierarchy that Access searches by creating a Registry key called RefLibPaths:

\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\8.0\Access\RefLibPaths

If Access sees this entry, it searches in the specified location before searching elsewhere. Create a string value within this key for each library fro which you want to establish a search path. The value name for the entry is the name of the library database, and the value data is the path to search.

You can bypass the reference model and "hard-wire" the location of a specific library without creating a reference to it by using a Registry key. Create the following key:

\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\8.0\Access\LoadOnStartup

Enter a value name under this key that is the path and file name for a library database, with the value data set as "RO" if the library is read-only, or "RW" for read/write. you can call procedures in the referenced library using the Run method and the qualified name of the procedure, for example:

Run "MyLib.Mda.MyProcedure"

This approach has limitations however. Because Run cannot return a value and because a library referenced like this through the Registry does not appear in the Object Browser, you cannot directly call a library function in a database with a Registry reference and no reference in the References collection.

Sources:
How Access 2002 resolves VBA references
How Access 2000 resolves VBA referenc
es

How Access 97 resolves VBA references

Access 97 Expert Solutions
(
Que Publishing) by Stan Leszynski

No comments: