Microsoft KB Archive/824255

= How Access resolves Visual Basic for Applications references =

Article ID: 824255

Article Last Modified on 4/27/2007

-

APPLIES TO


 * Microsoft Office Access 2007
 * Microsoft Office Access 2003
 * Microsoft Access 2002 Standard Edition
 * Microsoft Access 2000 Standard Edition
 * Microsoft Access 97 Standard Edition

-



This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).

Advanced: Requires expert coding, interoperability, and multiuser skills.

Important This article contains information about how to modify the registry. Make sure that you back up the registry before you modify it. Make sure that you know how to restore the registry if a problem occurs. For more information about how to back up, restore, and modify the registry, click the following article number to view the article in the Microsoft Knowledge Base:

256986 Description of the Microsoft Windows registry



SUMMARY
This article discusses the sequence of tasks that Microsoft Office Access 2007, Microsoft Office Access 2003, Microsoft Access 2002, Access 2000, or Access 97 performs to resolve the references in Microsoft Visual Basic for Applications (VBA).



MORE INFORMATION
Warning Serious problems might occur if you modify the registry incorrectly by using Registry Editor or by using another method. These problems might require that you reinstall the operating system. Microsoft cannot guarantee that these problems can be solved. Modify the registry at your own risk.

In Access, you can view the VBA references that are currently selected by using the Visual Basic Editor. To do this, follow these steps:
 * 1) Start Access.
 * 2) Open an Access database.
 * 3) Press ALT+F11 to open the Visual Basic Editor.
 * 4) In the Visual Basic Editor window, click References on the Tools menu.

In the References dialog box, you can see the references that are selected.

Note When you select a reference, you can also view the information that corresponds to the file that must be loaded to use the reference.

The pertinent file may be a type library, an object library, or a control library. The pertinent file for each reference is loaded according to the information that appears in the References dialog box. However, if the file is not found, Access searches for the file in different locations on your computer.

For each VBA reference that is selected, Access performs the following tasks:  Access verifies whether the referenced file is already loaded. Access verifies whether the  registry key exists if the referenced file is currently not loaded.

If the  registry key exists, Access searches for a named value that has the same name as the reference. If there is a match, Access loads the reference from the path that is mentioned in the named value.

Note You can manually add the  registry key to the registry and, then you can add the names and the locations of any add-ins or of any libraries that are under the   registry key. To do this, follow these steps:  Click Start, and then click Run. In the Open box, type regedit, and then click OK. In the Registry Editor window, locate the following registry key:

Access 2007:

Access 2003:

Access 2002:

Access 2000:

Access 97:

 Right-click the Access registry key, point to New, and then click Key. Name the newly created key RefLibPaths .</li> Click RefLibPaths.</li> Right-click anywhere in the right pane, and then click String value.</li> Name the newly created String value by using the same name as the VBA reference.</li> Right-click the String value that you created in step 8, and then click Modify.</li> In the Edit String dialog box, type the location of the file that must be loaded to correspond to the reference in VBA.

The registry value name must be the file name plus the extension. The location (value data) must be the path plus the file name. For example, if you set a reference to the Northwind sample database, you can add the following values: <ul> Value Name: Northwind.mdb</li> Value Data: C:\Program Files\Microsoft Office\Office11\Samples\Northwind.mdb</li></ul> </li> Repeat step 7 through step 10 to add the names and to add the locations of the appropriate add-ins or of the appropriate libraries as String values.</li> On the File menu, click Exit.</li></ol> </li> Access uses the SearchPath API to search for the referenced file if the  registry key does not exist or does not contain a correct reference. The following searches are performed. </li></ul>

Note Access does not require the  registry key if the file that you want to reference is located in any of the directories that are mentioned in the table.

If Access cannot find the reference, you receive the following error message when you compile the project or when you try to run a procedure:

Your Microsoft Office Access database or project contains a missing or broken reference to the file.


 * To ensure that your database or project works properly, you must fix this reference.

Note While the database is open, you receive the previous error message one time for each broken reference.

For example, if you open MyDatabase.mdb and MyDatabase.mdb is missing a reference to the Microsoft Calendar Control and to the Microsoft DAO library, you receive two error messages, one for each missing reference. You do not receive the error messages again unless you do not fix the references, you close the database, and then you reopen the database. If you fix the references and then you save the database, you do not receive the error messages the next time that you open the database.

The BrokenReference property
The Application object for Access has a BrokenReference property that tells you if any references are broken. To check the BrokenReference property, follow these steps: <ol> Start Access.</li> Open an Access database.</li> Press ALT+F11 to open the Visual Basic Editor.</li> Press CTRL+G to open the Immediate window.</li> In the Immediate window, type the following command, and then press ENTER:

?Application.BrokenReference

Notice that the BrokenReference property for the Application object returns True if there are missing references. Otherwise, the BrokenReference property returns False.</li></ol>

<div class="references_section">