PC Review


Reply
Thread Tools Rate Thread

Check My Code: Contacts Not Going to the Right Folder

 
 
audrie magno
Guest
Posts: n/a
 
      26th Sep 2005
In the code below, form field data is leaving Word and going to an Outlook contact list. Everything works EXCEPT it puts the new contact in my default contact folder instead of the custom folder... can anyone identify what I did wrong?

Public Sub AddContact()
Dim objOutlook As New Outlook.Application

Dim myNameSpace As NameSpace
Set myNameSpace = objOutlook.GetNamespace("MAPI")
Dim oOlFolder As MAPIFolder
Set oOlFolder = myNameSpace.Folders("Custom Contacts").Folders("Speakers") 'Here is my folder called "Custom Contacts", which is really a pst file on it's own, with a subfolder for contact items called "Speakers"
Dim objContact As ContactItem
Set objContact = objOutlook.CreateItem(olContactItem)

Dim FName As String
Dim HomeTelephone As String
Dim BusinessTelephone As String
Dim MailAddress As String
Dim aField As FormField
Dim myCategory As String
Dim Hour8Training As Integer
Dim Hour65Training As Integer


For Each aField In ActiveDocument.FormFields
If Trim(aField.Result) <> "" Then
If aField.Name = "chkPtdNewsletter" And aField.Result = "1" Then
myCategory = "Printed News"
Else
myCategory = "eNews"
End If

If aField.Name = "chk8HourTrainingYes" Then
Hour8Training = Val(aField.Result)
ElseIf aField.Name = "chk65HourTrainingYes" Then
Hour65Training = Val(aField.Result)
End If


If aField.Name = "NameField" Then
FName = aField.Result
ElseIf aField.Name = "Phone2Field" Then
HomeTelephone = aField.Result
ElseIf aField.Name = "PhoneField" Then
BusinessTelephone = aField.Result
ElseIf aField.Name = "MailingAddress" Then
MailAddress = aField.Result
End If

End If

Next

With objContact 'How do I direct the code to go into the Custom Folder?
.FullName = FName
.HomeTelephoneNumber = HomeTelephone
.BusinessTelephoneNumber = BusinessTelephone
.BusinessAddress = MailAddress
.Categories = myCategory
.UserProperties("8HourTraining") = Hour8Training
.UserProperties("65HourTraining") = Hour65Training
.Save
End With
Set objContact = Nothing
Set objOutlook = Nothing


End Sub
 
Reply With Quote
 
 
 
 
Sue Mosher [MVP-Outlook]
Guest
Posts: n/a
 
      26th Sep 2005
Use the Add method on the custom folder's Items collection to create the item:

Set objContact = oOlFolder.Items.Add

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx


"audrie magno" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
In the code below, form field data is leaving Word and going to an Outlook contact list. Everything works EXCEPT it puts the new contact in my default contact folder instead of the custom folder... can anyone identify what I did wrong?

Public Sub AddContact()
Dim objOutlook As New Outlook.Application

Dim myNameSpace As NameSpace
Set myNameSpace = objOutlook.GetNamespace("MAPI")
Dim oOlFolder As MAPIFolder
Set oOlFolder = myNameSpace.Folders("Custom Contacts").Folders("Speakers") 'Here is my folder called "Custom Contacts", which is really a pst file on it's own, with a subfolder for contact items called "Speakers"
Dim objContact As ContactItem
Set objContact = objOutlook.CreateItem(olContactItem)

Dim FName As String
Dim HomeTelephone As String
Dim BusinessTelephone As String
Dim MailAddress As String
Dim aField As FormField
Dim myCategory As String
Dim Hour8Training As Integer
Dim Hour65Training As Integer


For Each aField In ActiveDocument.FormFields
If Trim(aField.Result) <> "" Then
If aField.Name = "chkPtdNewsletter" And aField.Result = "1" Then
myCategory = "Printed News"
Else
myCategory = "eNews"
End If

If aField.Name = "chk8HourTrainingYes" Then
Hour8Training = Val(aField.Result)
ElseIf aField.Name = "chk65HourTrainingYes" Then
Hour65Training = Val(aField.Result)
End If


If aField.Name = "NameField" Then
FName = aField.Result
ElseIf aField.Name = "Phone2Field" Then
HomeTelephone = aField.Result
ElseIf aField.Name = "PhoneField" Then
BusinessTelephone = aField.Result
ElseIf aField.Name = "MailingAddress" Then
MailAddress = aField.Result
End If

End If

Next

With objContact 'How do I direct the code to go into the Custom Folder?
.FullName = FName
.HomeTelephoneNumber = HomeTelephone
.BusinessTelephoneNumber = BusinessTelephone
.BusinessAddress = MailAddress
.Categories = myCategory
.UserProperties("8HourTraining") = Hour8Training
.UserProperties("65HourTraining") = Hour65Training
.Save
End With
Set objContact = Nothing
Set objOutlook = Nothing


End Sub
 
Reply With Quote
 
=?Utf-8?B?RXJpYyBMZWdhdWx0IFtNVlAgLSBPdXRsb29rXQ==
Guest
Posts: n/a
 
      26th Sep 2005
You have to put it into the non-default Contacts folder by either of these
methods:

- call objContact.Move oOlFolder
- or use Set objContact = oOlFolder.Items.Add("IPM.Contact")

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"audrie magno" wrote:

> In the code below, form field data is leaving Word and going to an Outlook contact list. Everything works EXCEPT it puts the new contact in my default contact folder instead of the custom folder... can anyone identify what I did wrong?
>
> Public Sub AddContact()
> Dim objOutlook As New Outlook.Application
>
> Dim myNameSpace As NameSpace
> Set myNameSpace = objOutlook.GetNamespace("MAPI")
> Dim oOlFolder As MAPIFolder
> Set oOlFolder = myNameSpace.Folders("Custom Contacts").Folders("Speakers") 'Here is my folder called "Custom Contacts", which is really a pst file on it's own, with a subfolder for contact items called "Speakers"
> Dim objContact As ContactItem
> Set objContact = objOutlook.CreateItem(olContactItem)
>
> Dim FName As String
> Dim HomeTelephone As String
> Dim BusinessTelephone As String
> Dim MailAddress As String
> Dim aField As FormField
> Dim myCategory As String
> Dim Hour8Training As Integer
> Dim Hour65Training As Integer
>
>
> For Each aField In ActiveDocument.FormFields
> If Trim(aField.Result) <> "" Then
> If aField.Name = "chkPtdNewsletter" And aField.Result = "1" Then
> myCategory = "Printed News"
> Else
> myCategory = "eNews"
> End If
>
> If aField.Name = "chk8HourTrainingYes" Then
> Hour8Training = Val(aField.Result)
> ElseIf aField.Name = "chk65HourTrainingYes" Then
> Hour65Training = Val(aField.Result)
> End If
>
>
> If aField.Name = "NameField" Then
> FName = aField.Result
> ElseIf aField.Name = "Phone2Field" Then
> HomeTelephone = aField.Result
> ElseIf aField.Name = "PhoneField" Then
> BusinessTelephone = aField.Result
> ElseIf aField.Name = "MailingAddress" Then
> MailAddress = aField.Result
> End If
>
> End If
>
> Next
>
> With objContact 'How do I direct the code to go into the Custom Folder?
> .FullName = FName
> .HomeTelephoneNumber = HomeTelephone
> .BusinessTelephoneNumber = BusinessTelephone
> .BusinessAddress = MailAddress
> .Categories = myCategory
> .UserProperties("8HourTraining") = Hour8Training
> .UserProperties("65HourTraining") = Hour65Training
> .Save
> End With
> Set objContact = Nothing
> Set objOutlook = Nothing
>
>
> End Sub

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check Names can't find contacts folder =?Utf-8?B?dGNhcnA=?= Microsoft Outlook Contacts 12 24th Dec 2010 12:16 AM
Outlook should check names from more than one Contacts folder Guido Microsoft Outlook Contacts 3 17th Mar 2010 01:44 AM
All contacts from Contact Folder to BCC by code Gil Araujo Microsoft Outlook VBA Programming 1 19th Jan 2010 07:12 PM
problem with code to link to an Outlook contacts folder shanej Microsoft Access Database Table Design 2 14th Jul 2006 12:17 AM
setting my code to access contacts from a a different folder. =?Utf-8?B?Q2hhcmxpZQ==?= Microsoft Outlook VBA Programming 3 1st May 2006 05:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:36 AM.