Getting closer!!! Now, it seems to be finding the record (if present) but it
is adding it to the default olContactItem.
How can I tell what GetFolder is finding? Is there a way to display the
value? And what SHOULD it look like Iif I am calling the directory the right
name?
Also, in the portion that adds the contact:
If objContact Is Nothing Then
MsgBox "Adding ..."
Set objContact = Application.CreateItem(olContactItem)
With objContact
.FullName = objSRecip.Name
.Email1Address = strAddress
.Save
End With
End If
how do I force a location for the item?
below is the module as it stands.
Thanks
Bruce
------------------------
Sub AddRecipToContacts(objMail As MailItem)
Dim strFind As String
Dim strAddress As String
Dim objSMail As Redemption.SafeMailItem
Dim objSRecip As Redemption.SafeRecipient
Dim objNS As NameSpace
Dim colContacts As Items
Dim objContact As ContactItem
Dim i As Integer
' process message recipients
Set objSMail = CreateObject("Redemption.SafeMailItem")
objMail.Save
objSMail.Item = objMail
Set objNS = Application.GetNamespace("MAPI")
'Set colContacts = objNS.GetDefaultFolder(olFolderContacts).Items
Set objFolder = GetFolder("Personal Folders\BPContacts")
If Not objFolder Is Nothing Then
Set colContacts = objFolder.Items
MsgBox "Got info for Personal Folders\BPContacts"
If Not colContacts Is Nothing Then
MsgBox "colcontacts has value"
Else
MsgBox "colcontacts is empty"
Stop
End If
Else
MsgBox "Could not get a MAPIFolder object for Personal
Folders\BPContacts"
End If
For Each objSRecip In objSMail.Recipients
' check to see if the recip is already in Contacts
strAddress = objSRecip.Address
For i = 1 To 3
strFind = "[Email" & i & "Address] = " & _
AddQuote(strAddress)
Set objContact = colContacts.Find(strFind)
'Stop
If Not objContact Is Nothing Then
Stop
Exit For
End If
Next
Stop
' if not, add it
If objContact Is Nothing Then
MsgBox "Adding ..."
Set objContact = Application.CreateItem(olContactItem)
With objContact
.FullName = objSRecip.Name
.Email1Address = strAddress
.Save
End With
End If
'Stop
Set objContact = Nothing
Next
Set objSMail = Nothing
Set objSRecip = Nothing
Set objNS = Nothing
Set colContacts = Nothing
End Sub
It's almost always better in Outlook to get objects one at a time before
using their properties, e.g.
Set objFolder = GetFolder("Personal Folders\BPContacts")
If Not objFolder Is Nothing Then
Set colContacts = objFolder.Items
Else
MsgBox "Could not get a MAPIFolder object for Personal
Folders\BPContacts"
End If
How did you declare colContacts?
--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at
http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx
BruceJ said:
Sue,
Am I doing this correctly? How would I use the getfolder() within the
function AddRecipToContacts to set the desired contact folder (it is on the
root of my Personal Folders) so I thought it should be "personal
folders/BPConstacts"
' Set colContacts = objNS.GetDefaultFolder(olFolderContacts).Items
Set colContacts = GetFolder("Personal Folders\BPContacts").Items
I get an error13 Type mismatch
If I do
Set colContacts = GetFolder("BPContacts").Items
I get a run time error 91 object varible or With block varible not set