A
Alan Z. Scharf
1. I'm having a problem getting items saved in the dedired Outlook folder
from Access records.
2. The output from Access to Outlook works perfectly - BUT all the records
go intothe main Outlook Contacts folder.
The folder I want them to go to is "TEST" in \Personal
Folders\Contacts\TEST.
3. I'm using following code to set folder:
Dim App As New Outlook.Application
Dim Ns As Outlook.NameSpace
Dim Fldr As Outlook.MAPIFolder
Set Ns = App.GetNamespace("MAPI")
Set Fldr = Ns.GetDefaultFolder(olFolderContacts)
Set Fldr = Fldr.Folders("TEST")
Any insight would be appreciated.
Complete code is listed below.
Thanks very much.
Alan
------------------------------------------------------------------------
' WRITE ACCESS CONTACTS TO OUTLOOK
Private Sub cmdUpdateOutlook_Click()
'''' Purpose: To update Outlook with aCCESS Contacts
' Set up ADO objects
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Set cnn = CurrentProject.Connection
strSQL = ("SELECT * FROM dbo.qryUpdateOutlook")
Set rst = New ADODB.Recordset
rst.Open strSQL, cnn
' Set Up Counter for status bar
Dim iCounter As Long
iCounter = 1
' Set up Outlook objects
Dim App As New Outlook.Application
Dim Ns As Outlook.NameSpace
Dim Fldr As Outlook.MAPIFolder
Set Ns = App.GetNamespace("MAPI")
Set Fldr = Ns.GetDefaultFolder(olFolderContacts)
Set Fldr = Fldr.Folders("TEST")
' Loop through Access records
Do Until rst.EOF
' Create new contact item
Set Item = App.CreateItem(olContactItem)
' Specify which form to use
Item.MessageClass = "IPM.Contact"
' Create all built-in Outlook fields fom Access record
With Item
.CompanyName = Nz(rst("Company"))
.FirstName = Nz(rst("FirstName"))
.LastName = Nz(rst("LastName"))
.BusinessAddressStreet = Nz((rst("Address1") & Chr(13) &
rst("Address2")))
.BusinessAddressCity = Nz(rst("City"))
.BusinessAddressState = Nz(rst("State"))
.............................................................................
..................
.Email2Address = Nz(rst("HomeEmail"))
.WebPage = Nz(rst("Website"))
' Save item in Outlook
.Save
End With
' Rewrite status bar
SetStatusBar ("Adding " & CStr(iCounter) & " of " &
CStr(rst.RecordCount) & " Contacts")
' Get next record
rst.MoveNext
iCounter = (iCounter + 1)
Loop
' Close
rst.Close
Set rst = Nothing
Set cnn = Nothing
End Sub
from Access records.
2. The output from Access to Outlook works perfectly - BUT all the records
go intothe main Outlook Contacts folder.
The folder I want them to go to is "TEST" in \Personal
Folders\Contacts\TEST.
3. I'm using following code to set folder:
Dim App As New Outlook.Application
Dim Ns As Outlook.NameSpace
Dim Fldr As Outlook.MAPIFolder
Set Ns = App.GetNamespace("MAPI")
Set Fldr = Ns.GetDefaultFolder(olFolderContacts)
Set Fldr = Fldr.Folders("TEST")
Any insight would be appreciated.
Complete code is listed below.
Thanks very much.
Alan
------------------------------------------------------------------------
' WRITE ACCESS CONTACTS TO OUTLOOK
Private Sub cmdUpdateOutlook_Click()
'''' Purpose: To update Outlook with aCCESS Contacts
' Set up ADO objects
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Set cnn = CurrentProject.Connection
strSQL = ("SELECT * FROM dbo.qryUpdateOutlook")
Set rst = New ADODB.Recordset
rst.Open strSQL, cnn
' Set Up Counter for status bar
Dim iCounter As Long
iCounter = 1
' Set up Outlook objects
Dim App As New Outlook.Application
Dim Ns As Outlook.NameSpace
Dim Fldr As Outlook.MAPIFolder
Set Ns = App.GetNamespace("MAPI")
Set Fldr = Ns.GetDefaultFolder(olFolderContacts)
Set Fldr = Fldr.Folders("TEST")
' Loop through Access records
Do Until rst.EOF
' Create new contact item
Set Item = App.CreateItem(olContactItem)
' Specify which form to use
Item.MessageClass = "IPM.Contact"
' Create all built-in Outlook fields fom Access record
With Item
.CompanyName = Nz(rst("Company"))
.FirstName = Nz(rst("FirstName"))
.LastName = Nz(rst("LastName"))
.BusinessAddressStreet = Nz((rst("Address1") & Chr(13) &
rst("Address2")))
.BusinessAddressCity = Nz(rst("City"))
.BusinessAddressState = Nz(rst("State"))
.............................................................................
..................
.Email2Address = Nz(rst("HomeEmail"))
.WebPage = Nz(rst("Website"))
' Save item in Outlook
.Save
End With
' Rewrite status bar
SetStatusBar ("Adding " & CStr(iCounter) & " of " &
CStr(rst.RecordCount) & " Contacts")
' Get next record
rst.MoveNext
iCounter = (iCounter + 1)
Loop
' Close
rst.Close
Set rst = Nothing
Set cnn = Nothing
End Sub