-
Apr 27th, 2006, 02:33 AM
#1
[FAQ's: OD] How do I Export ContactItems to a Access database?
Using ADO for this example we can easily export our primary Outlook contacts to an Access database. You can use any technology to perform the database connection and inserts.
Outlook VBA Code Example:
VB Code:
'Behind ThisOutlookSession
Option Explicit
'Add a reference to MS ActiveX Data Objects 2.x Library
Public Sub ExportContacts()
'Connect to your database
Dim oCnn As ADODB.Connection
Set oCnn = New ADODB.Connection
oCnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyDB.mdb;User Id=Admin;Password=;"
oCnn.Open
'Connect to your default Contacts folder
Dim oConFolder As Outlook.MAPIFolder
Dim oContact As Outlook.ContactItem
Dim sSQL As String
Set oConFolder = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderContacts)
'Iterate through the primary Outlook Contacts
For Each oContact In oConFolder.Items
'Table1 must already exist with the correct fields/Data types
sSQL = "INSERT INTO Table1"
sSQL = sSQL & " (FirstName, LastName, CompanyName, Email1Address, Phone, FAX)"
sSQL = sSQL & " VALUES('" & oContact.FirstName '
sSQL = sSQL & "', '" & oContact.LastName '
sSQL = sSQL & "', '" & oContact.CompanyName '
sSQL = sSQL & "', '" & oContact.Email1Address '
sSQL = sSQL & "', '" & oContact.BusinessTelephoneNumber '
sSQL = sSQL & "', '" & oContact.BusinessFaxNumber & "')" '
oCnn.Execute sSQL
Next
Set oContact = Nothing
Set oConFolder = Nothing
oCnn.Close
Set oCnn = Nothing
End Sub
Last edited by RobDog888; May 22nd, 2006 at 03:11 AM.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|