Previous Thread:   OPening a VBA form in outlook

9/25/2005 7:07:25 PM    Check My Code: Contacts Not Going to the Right Folder




9/26/2005 1:23:22 PM    Re: Check My Code: Contacts Not Going to the Right Folder
Use the Add method on the custom folder's Items collection to create the =  
  
item:=20  
  
Set objContact =3D oOlFolder.Items.Add  
  
--=20  
  
Sue Mosher, Outlook MVP  
  
Author of Configuring Microsoft Outlook 2003  
  
http://www.turtleflock.com/olconfig/index.htm  
  
and Microsoft Outlook Programming - Jumpstart for=20  
  
Administrators, Power Users, and Developers  
  
http://www.outlookcode.com/jumpstart.aspx  
  
"audrie magno" <magnoa@saccounty.net> wrote in message =  
  
news:eJkyM8jwFHA.1456@TK2MSFTNGP11.phx.gbl...  
  
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  
  
=20  
  
Dim myNameSpace As NameSpace  
  
Set myNameSpace =3D objOutlook.GetNamespace("MAPI")  
  
Dim oOlFolder As MAPIFolder  
  
Set oOlFolder =3D 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 =3D objOutlook.CreateItem(olContactItem)  
  
=20  
  
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  
  
=20  
  
=20  
  
For Each aField In ActiveDocument.FormFields  
  
If Trim(aField.Result) <> "" Then  
  
If aField.Name =3D "chkPtdNewsletter" And aField.Result =3D =  
  
"1" Then  
  
myCategory =3D "Printed News"  
  
Else  
  
myCategory =3D "eNews"  
  
End If  
  
=20  
  
If aField.Name =3D "chk8HourTrainingYes" Then  
  
Hour8Training =3D Val(aField.Result)  
  
ElseIf aField.Name =3D "chk65HourTrainingYes" Then  
  
Hour65Training =3D Val(aField.Result)  
  
End If  
  
=20  
  
=20  
  
If aField.Name =3D "NameField" Then  
  
FName =3D aField.Result  
  
ElseIf aField.Name =3D "Phone2Field" Then  
  
HomeTelephone =3D aField.Result  
  
ElseIf aField.Name =3D "PhoneField" Then  
  
BusinessTelephone =3D aField.Result  
  
ElseIf aField.Name =3D "MailingAddress" Then  
  
MailAddress =3D aField.Result  
  
End If  
  
=20  
  
End If  
  
Next  
  
With objContact  'How do I direct the code to go into the Custom =  
  
Folder?  
  
.FullName =3D FName  
  
.HomeTelephoneNumber =3D HomeTelephone  
  
.BusinessTelephoneNumber =3D BusinessTelephone  
  
.BusinessAddress =3D MailAddress  
  
.Categories =3D myCategory  
  
.UserProperties("8HourTraining") =3D Hour8Training  
  
.UserProperties("65HourTraining") =3D Hour65Training  
  
.Save  
  
End With  
  
Set objContact =3D Nothing  
  
Set objOutlook =3D Nothing  
  
=20  
  
=20  
  
End Sub