Problem when changing Message Class for contact Items.

  • Thread starter Thread starter Andrew Cushen
  • Start date Start date
A

Andrew Cushen

Hi all-

I'm back again! ;-)

I have some code I got from Gordon Padwick and Ken
Slovak's book, "Programming Microsoft Outlook 2000", that
changes the message class of an item so that you can use a
form you've created for existing Task items.

I have adapted it for changing Contact items to use a
Contact form I've created, called "SendFax".

I'm using Outlook 2000, BTW.

The code runs, but it always fails to change 4 or 5
contacts out of a few hundred. When I write the Err.Number
& .Description to the screen at the end of processing it
tells me "Run-time Error '13': Type mismatch". Yet it
correctly processes all the other contacts!

The code follows:

******************[ CODE BEGIN ]************************
Err.Clear

Dim appOl As Outlook.Application
Dim nmsNS As NameSpace
Dim strNew As String
Dim fldContacts As MAPIFolder
Dim itmItems As Items
Dim itmContact As ContactItem

strNew = "IPM.Contact.SendFax"

Set appOl = CreateObject("Outlook.Application")
Set nmsNS = appOl.GetNamespace("MAPI")
Set fldContacts = nmsNS.GetDefaultFolder
(olFolderContacts)
Set itmItems = fldContacts.Items

'Loop through items in the folder:
For Each itmContact In itmItems
With itmContact
' Message class needs to be changed - ?
If .MessageClass <> strNew Then
' Change the message class:
.MessageClass = strNew
' Save it
.Save
End If
End With
If Err.Number <> 0 Then
MsgBox Err.Number & " " & Err.Description &
vbCrLf & _
itmContact.FullNameAndCompany
End If
Next

If Err.Number = 0 Then
MsgBox "All done."
Else
MsgBox Err.Number & " " & Err.Description
End If

******************[ CODE END ]**********************

Anyone have any idea what's going on here?

Thanks,

-Andrew
 
Your contacts folder contains distribution lists as well as contacts.
Declare itmContact as Object and check the value of the Class property
before doing anything to it.
 
Your contacts folder contains distribution lists as well
as contacts.
Declare itmContact as Object and check the value of the Class property
before doing anything to it.

AGGGHH! You're right! I didn't realize that, but it makes
perfect sense.

And it fixed the problem completely.

Thanks again, Sue!

-Andrew
ps. How do you guys REMEMBER all this minutiae? I guess
it's because you've been doing it every day for years, and
I haven't yet, but still... :-)
 
Back
Top