Share this Page URL

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

Using Visual Basic to Manage Data 595 3. The code we've added to the procedure declares object variables for an instance of Outlook, the Outlook namespace, the MAPI folder type, and the type of item we'll use--in this example, a contact item. The code then assigns to these variables references to the appropriate objects. The NameSpace object is used for accessing data sources in Outlook. MAPI is the only type of namespace supported in Outlook, and this value is provided to the GetNameSpace method in the second of the four Set statements. By using the NameSpace object's GetDefault- Folder method, the MAPIFolder object (myFolder) is set to the constant olFolderContacts be- cause we're working with a contact item in this example. The code then uses the Outlook Application object's CreateItem method to create a new contact item. After the line that reads Set cntItem = myOlApp. CreateItem (olContactItem), enter the following lines of code: With cntItem .FullName = Me.ContactName .JobTitle = Me.ContactTitle .BusinessAddress = _ Me.Address & Chr(13) & _ Me.City & Chr(13) & _ Me.Country & Chr(13) & _ Me.PostalCode .BusinessTelephoneNumber = Me.Phone .Save .Display End With Set Set Set Set cntItem = Nothing myFolder = Nothing myNameSpace = Nothing myOlApp = Nothing The first four lines of the With...End With block set properties of the contact item object by