Trouble setting Outlook Folder from Access

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
 
S

Sue Mosher [MVP-Outlook]

To create a new item in a specific folder, use the Add method on the target
folder's Items collection. You can use the code at
http://www.outlookcode.com/d/code/getfolder.htm to walk the folder hierarchy
and return the MAPIFolder corresponding to a given path string.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
A

Alan Z. Scharf

Sue,

Thanks for your reply.

I'm still having a probllem getting the new Items into in the desired
folder.

1. I had already tried the GetFolder code.
I have also tried GetFolderFromID with the long itemc ode.

2. My 'Fldr' object variables is calculated correctly with both methods ,
but contact item still goes into default "Personal Items"\Contacts"

3. QUESTIONS: :Am I doning something wrong in specifying wher the Item is
created?
Is there some Add statement required for the specified folder?

4. The placement of GetFolder() is as below.
I also tried placing it within the loop.

Thanks again very much.
I have ordered your book, but am trying to find the solution before the book
arrives.

Alan


Roght now, I have:

GETFOLDER CODE
-----------------------


Set Fldr = GetFolder("Personal Folders/Contacts/TEST")
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"))
 
S

Sue Mosher [MVP-Outlook]

Repeating:

In other words, MAPIFolder.Items.Add, not CreateItem.
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top