When you set a reference to another application's type library, you can use the objects supplied by that application in your code. For example, if you set a reference from Microsoft Access to the Microsoft Excel library, you can then use Microsoft Excel objects through Automation (formerly called OLE Automation). If you set a reference to a Visual Basic project in another Microsoft Access database, you can call its public procedures. If you set a reference to an ActiveX control, you can use that control on Microsoft Access forms.
You can set a reference from Microsoft Access while the Microsoft Visual Basic Editor is open, or you can set a reference in Visual Basic code.
Setting a Reference from Microsoft Access
To set a reference to an application's type library:
Setting a Reference from Visual Basic
To set a reference from Visual Basic, you create a new Reference object representing the desired reference. The References collection contains all currently set references.
To create a new Reference object, use either the AddFromFile or AddFromGUID method of the References collection. To remove a Reference object, use the Remove method.
Advantages of Setting References
Your Automation code will run faster if you set a reference to another application's type library before you work with its objects. If you've set a reference, you can declare an object variable representing an object in the other application as its most specific type. For example, if you're writing code to work with Microsoft Excel objects, you can declare an object variable of type Excel.Application by using the following syntax only if you've created a reference to the Microsoft Excel type library:
Dim appXL As New Excel.Application
If you haven't set a reference to the Microsoft Excel type library, you must declare the variable as a generic variable of type Object. The following code runs more slowly:
Dim appXL As Object
Additionally, if you set a reference to an application's type library, all of its objects, as well as their methods and properties, are listed in the Object Browser. This makes it easy to determine what properties and methods are available to each object.
Since Microsoft Access is an COM component that supports Automation, you can also set a reference to its type library from another application and work with Microsoft Access objects from that application.