| | Awarded by Microsoft since 2005: |  |
| | VBOffice Info | | Visitors | 1409164 | | Impressions | 5189504 |
| |
|
| |
| Author: Michael Bauer | Homepage | | Date: 23.08.2008 | Accessed: 20181 | | | | Description
With a few lines of code you may copy recordsets from an Access database to Outlook. In this sample, the fields "Fullname" and "EMailAddress" from the table "Customers" will be read, and for every found recordset a new contact will be created in Outlook.
In the procedure "ConnectDB", change the values for the variables "File" (file name of your Access database), "Fields" (field names to be read), and "Table" (name of the database table). Repeat the field names in the procedure "AddContactsFromAccess", and assign the values to the appropriate ContactItem properties.
You also need to add a reference to a "Microsoft ActiveX Data Objects 2.x Library" via Tools/References. If there's more than one library of that type, just choose the most current one. |
Public Sub AddContactsFromAccess()
Dim Contact As Outlook.ContactItem
Dim Name As String
Dim Fields As ADODB.Fields
ConnectDB
Set Fields = m_Rs.Fields
While Not m_Rs.EOF
Set Contact = Application.CreateItem(olContactItem)
Name = "Fullname"
If IsNull(Fields(Name).Value) = False Then
Contact.FullName = Fields(Name).Value
End If
Name = "EMailAddress"
If IsNull(Fields(Name).Value) = False Then
Contact.FullName = Fields(Name).Value
End If
Contact.Save
m_Rs.MoveNext
Wend
m_Rs.Clone: Set m_Rs = Nothing
m_Cn.Close: Set m_Cn = Nothing
End Sub
Private Sub ConnectDB()
Dim File As String
Dim Table As String
Dim Fields As String
File = "c:\test.mdb"
Fields = "Fullname, EMailAddress"
Table = "Customers"
Set m_Cn = New ADODB.Connection
With m_Cn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = File
.CursorLocation = adUseClient
.Mode = adModeShareDenyNone
.Open
End With
Set m_Rs = New ADODB.Recordset
With m_Rs
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockOptimistic
Set .ActiveConnection = m_Cn
.Open ("SELECT " & Fields & " FROM " & Table)
End With
End Sub
|
| | |
| | |  | ReplyAll alerts you before unintentionally replying all, or if you are a confidential BCC recipient of the ... [more] |
| | |  | Access the master category list in the blink of an eye, share your categories in a network, get a reminder service, and ... [more] |
| | |  | SAM automatically sets the sender, signature, and folder for sent items, for instance based on the recipient ... [more] |
| | |  | OLKeeper reliably prevents users from closing their Outlook window and thus possibly missing reminders or ... [more] |
| |
|