Sue, I am trying to do the same thing and I cannot get the Contact to be
created in a different folder either. Here is the code:
Dim ol As New Outlook.Application
Dim olns As Outlook.NameSpace
Dim cf As Outlook.MAPIFolder
Dim c As Outlook.ContactItem
'Dim Prop As Outlook.UserProperty
Set olns = ol.GetNamespace("MAPI")
With rst
.MoveFirst
' Loop through the Microsoft Access records.
Do While Not .EOF
' Create a new Contact item.
Set c = ol.CreateItem(olContactItem)
' Specify which Outlook form to use.
c.MessageClass = "IPM.Contacts"
' Create all built-in Outlook fields.
If ![FirstName] <> "" Then c.FirstName = ![FirstName]
If ![LastName] <> "" Then c.LastName = ![LastName]
If ![EmailAddress1] <> "" Then c.Email1Address = ![EmailAddress1]
If ![Department] <> "" Then c.Department = ![Department]
If ![JobTitle] <> "" Then c.JobTitle = ![JobTitle]
' Save the contact.
c.Save
.MoveNext
Loop
End With
It creates it in my default Contact folder. I want to create it in a
Public
Folder. I can get to the Public Folder to delete items ok, I just can't
create contacts programmatically. (The code I can delete with is below
Sub DeletePublicFolderCRMContacts()
Set ol = New Outlook.Application
Set olns = ol.GetNamespace("MAPI")
Set TestFolder = olns.Folders("Public Folders").Folders("All Public
Folders").Folders("CRM Contacts")
' Set TestFolder = olns.GetDefaultFolder(olFolderContacts)
Set TestItems = TestFolder.Items
NumItems = TestItems.Count
For i = NumItems To 1 Step -1
TestItems(i).Delete
Next
End Sub
Thank you.
Sue Mosher said:
Show the code you're using to create the individual contact records. My
guess is that you're not using the method I suggested, but let's look at
the
code together.
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx
Thanks, but even after I use the code that you suggested,
the records from Access are created in the default folder
Contacts. Is there a way to make the sub folder Students
that is created to be the folder where the records are
created?
Thanks, Joel
PS. I am using code that came from MS knowledge base on
how to import data from Access into Outlook; it allows
one to import into custom fields but by default the
records are created in the default Contacts folder.
-----Original Message-----
Try:
Set newfolder = cf.Folders.Add("students")
To create a new item in a non-default folder, use the
Add method on the
target folder's Items collection.
message
TWIMC:
TIA...I have code to create contact records from Access
database. The code (portion below) creates the records
in the default Contacts folder. Is there a way to set
the current folder to a subfolder to the default
Contacts
folder??
Set olns = ol.GetNamespace("MAPI")
Set cf = olns.GetDefaultFolder(olFolderContacts)
ie I will create or code to create "students" subfolder
which will be subfolder to default Contacts folder.