Improving Your Outlook

Importing and exporting Outlook items has many uses. You can share data between several users, back up your Outlook data, and transfer data to or from external applications. Outlook is highly customizable, having the capability to use custom forms to store additional enterprise-specific data not found in the standard contact form. However, importing and exporting information stored in custom fields isn't as simple as it might sound. You cannot actually use Outlook's Import and Export Wizard to work with data in custom forms. User-defined fields will never appear when you attempt to map custom fields. If you attempt to export from a custom form, you won't even get Outlook's default fields, let alone the custom fields.

There are several third-party tools you can use to export and import custom data. However, the easiest method is to simply write some VBA code to import or export custom field data.

NOTE

One fast method to export data in custom fields is to create a table view with all of your custom fields. Then simply select one item in the view, press Ctrl+A to select all items, copy the items, and paste them into an Excel spreadsheet. Although it isn't the ideal method of exporting custom information, it's quick and reasonably accurate.


How your code will be written depends on the specific source and destination programs. If you're attempting to import Access data into Outlook, it's probably easier to write the code in Outlook VBA. If you're exporting Outlook data into Excel, you might want to start with Excel's VBA environment. The specific program you'll choose depends on how familiar you are with the various development environments. The following code sample imports five custom fields from an Access database into a custom Outlook contact form. The code is written in Outlook 2003's VBA environment.

 Sub ImportContacts() Dim olNS As Outlook.NameSpace Dim olCTFolder As Outlook.MAPIFolder Dim olProspectFolder As Outlook.MAPIFolder Dim olCTItem As Outlook.ContactItem Dim objConn As ADODB.Connection Dim objRST As ADODB.Recordset Dim objfld As ADODB.Field Dim strSQL As String Set olNS = Application.GetNamespace("MAPI") Set olCTFolder = olNS.GetDefaultFolder(olFolderContacts) Set olProspectFolder = olCTFolder.Folders("Prospects") Set objConn = CreateObject("ADODB.Connection") Set objRST = CreateObject("ADODB.Recordset") strSQL = "SELECT * FROM Contacts;" objConn.Provider = "Microsoft.Jet.OLEDB.4.0" objConn.Open "C:\Documents and Settings\Patricia\My Documents\Contacts.mdb" objRST.Open strSQL, objConn, adOpenForwardOnly, adLockOptimistic objRST.MoveFirst While Not objRST.EOF     Set olCTItem = olProspectFolder.Items.Add("IPM.Contact.Prospects")     olCTItem.Display     olCTItem.FullName = objRST.Fields("ContactName")     olCTItem.BusinessAddressStreet = objRST.Fields("Address1")     olCTItem.BusinessAddressCity = objRST.Fields("City")     olCTItem.BusinessAddressState = objRST.Fields("State")     olCTItem.BusinessAddressPostalCode = objRST.Fields("Zip")     olCTItem.UserProperties("SalesRepresentative") = objRST.Fields("SalesRepresentative")     olCTItem.UserProperties("AnnualSales") = objRST.Fields("AnnualSales")     olCTItem.UserProperties("LastContactDate") = objRST.Fields("LastContactDate")     olCTItem.UserProperties("NextScheduledContact") = objRST.Fields("NextScheduledContact")     objRST.MoveNext     olCTItem.Close olSave Wend objRST.Close objConn.Close Set objRST = Nothing Set objConn = Nothing Set olCTItem = Nothing Set objProspectFolder = Nothing Set objCTFolder = Nothing Set objNS = Nothing End Sub 

Using this or similar code, you can create custom contact items directly from a Microsoft Access database. You could take this same code and change it slightly to write custom contact data to your Access database directly from Outlook.



Special Edition Using Microsoft Office Outlook 2003
Special Edition Using Microsoft Office Outlook 2003
ISBN: 0789729563
EAN: 2147483647
Year: 2003
Pages: 426

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net