Share this Page URL

Chapter 17. Using Visual Basic to Manage... > Using Visual Basic to Work with Data... - Pg. 594

Using Visual Basic to Manage Data 594 Still, a missing reference can cause code not to run, leading to an error message. You can add a reference to an object library in code by using the Access References collection, indicating which object library you need a reference to. Here's an example, which adds a reference to the object library for Excel: Dim refs As Access.References Set refs = Application.References refs.AddFromFile "C:\Program Files\Microsoft Office\Office11\Excel.exe" The path and file name of the object library is shown at the bottom of the References dialog box in the Visual Basic Editor. You could include this code in a procedure that uses objects from Excel's object model. Building an Outlook Contact List from Access Using Visual Basic code that's similar to the code presented in Chapter 5, you can add a contact item--or a task or calendar item--to Outlook. In a database such as the HelloWorld example, which is in part designed to help manage workflow, you could add tasks related to specific campaigns to the Outlook Tasks folder for the individuals assigned to carry out the work. In a database such as the Northwind database, in which customer data such as names, addresses, and phone numbers is stored, you could create a Visual Basic procedure that would use the data to create a contact item in Outlook. In this way, you wouldn't need to reenter customer data as a contact. You could take advantage of the fact that customer data was already stored in Access. In the next set of steps, we'll describe code that adds a contact to Outlook. We'll use the customer data that's stored in the Northwind sample database as the source. You need to have Outlook installed on your computer for the code presented in this section to work. Add a customer contact to Outlook from Access 1. In the HelloWorld17 database, select the form named Customers in the Database window,