PC Review


Reply
Thread Tools Rate Thread

Create Outlook Contact Error 13

 
 
=?Utf-8?B?RXJpYw==?=
Guest
Posts: n/a
 
      10th Nov 2007
I have had difficulty getting this to work. Can anybody tell me what I have
done wrong? I want to create a contact from excel and have it saved to
Outlook Public Folders.

Sub CreateOutlookContact()
'called from onsheet btn
'early binding to Microsoft Outlook 12.0 Object library (Outlook 2007)

Dim olApp As Outlook.Application
Dim olCi As Outlook.ContactItem
Dim olNs As Namespace
Dim Fldr As MAPIFolder
Dim iAnswer As Integer

Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set Fldr = olNs.Folders("Public Folders").Folders("All Public
Folders").Folders("The Solar Company").Folders("TSC-Contacts")

For Each olCi In Fldr.Items
If olCi.FirstName = [PrimaryFirst] And olCi.LastName = [PrimaryLast]
Then
iAnswer = MsgBox("A contact with that first and last name
already exists." & vbCrLf & vbCrLf & "Click Ok to overwrite it.", vbOKCancel)
If iAnswer = vbOK Then
olCi.Delete
Else
Exit Sub
End If
End If
Next olCi

Set olCi = olApp.CreateItem(olContactItem)

With olCi
.FirstName = [PrimaryFirst]
.LastName = [PrimaryLast]
.HomeTelephoneNumber = [PrimaryHomePhone]
.BusinessFaxNumber = [PrimaryFax]
.MobileTelephoneNumber = [PrimaryMobile]
.BusinessTelephoneNumber = [PrimaryBusinessPhone]
.Email1Address = [PrimaryEmail]
.Body = "Second Owner Information:" & vbCrLf & _
"First Name: " & [SecondaryFirst] & vbCrLf & _
"Last Name: " & IIf([SecondaryLast] = "", [PrimaryLast],
[SecondaryLast]) & vbCrLf & _
"Phone Number: " & [SecondaryPhone] & vbCrLf & _
"APN: " & [APN]
.Business2TelephoneNumber = [SecondaryPhone]
.MailingAddressStreet = [MailingStreet]
.MailingAddressCity = [MailingCity]
.MailingAddressPostalCode = [MailingZip]
.OtherAddressStreet = [JobStreet]
.OtherAddressCity = [JobCity]
.OtherAddressPostalCode = [JobZip]

.Categories = [OutlookCat]

.Save

iAnswer = MsgBox([PrimaryFirst] & " " & [PrimaryLast] & " has been
added to your Outlook Contacts." & vbCrLf & vbCrLf & "Do you want to display
the contact now?", vbYesNo)
If iAnswer = vbYes Then
.Display
End If
End With

Set olCi = Nothing
Set olApp = Nothing

End Sub

 
Reply With Quote
 
 
 
 
=?Utf-8?B?RXJpYw==?=
Guest
Posts: n/a
 
      10th Nov 2007
I should have added the line with

Next olCi

Is highligted when I debug
 
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
Create a Fax from Outlook Contact Diana Microsoft Outlook BCM 0 27th Jan 2010 06:26 PM
Create Outlook Contact CrazyAccessProgrammer Microsoft Access VBA Modules 1 26th Feb 2009 03:01 AM
Create Outlook Contact from Excel =?Utf-8?B?RXJpYw==?= Microsoft Excel Misc 3 7th Nov 2007 03:24 AM
Outlook 2007 - Business Contact Manager - Create contact from exis =?Utf-8?B?YWx1bWludW1wb3Jr?= Microsoft Outlook Discussion 0 20th Feb 2007 05:34 PM
How to create a New Fax to Contact in Outlook =?Utf-8?B?Y2RpYWw=?= Microsoft Outlook Discussion 1 5th Jan 2005 12:30 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:14 AM.