Delete some UD fields

A

acb

Hi,

I have created a few UD fields in Outlook 2003 and would like to delete
them. After some searching, I created the code below. Thing is that it
seems to execute correctly (replacing objProperty.Delete with MsgBox
objProperty.Name pops us values), but upon execution nothing seems to
be happening.

Also, I am getting the error "Run Time Error '13'" - Type mismatch. It
seems that program execution still continues in debug mode. objContact
has a value of Nothing.

Sub DelUDFld()
Dim olApp As Outlook.Application
Dim objContact As Outlook.ContactItem
Dim objContacts As Outlook.MAPIFolder
Dim objNameSpace As Outlook.NameSpace
Dim objProperty As Outlook.UserProperty
Dim NumItems, i As Integer

Set olApp = CreateObject("Outlook.Application")
Set objNameSpace = olApp.GetNamespace("MAPI")
Set objContacts = objNameSpace.GetDefaultFolder(olFolderContacts)
For Each objContact In objContacts.Items
For Each objProperty In objContact.UserProperties
If objProperty.Name <> "LoginName" Then
'MsgBox objProperty.Name
objProperty.Delete

End If
Next objProperty
Set objProperty = Nothing
Next objContact
Set objContact = Nothing


End Sub

Any help appreciated

Regards,
Al
 
S

Sue Mosher [MVP-Outlook]

I don't see any statement to save the item after you make the changes to it.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
A

acb

Thanks for the info. Didn't know you had to save;

you wouldn't know what the statement is; it will avoid me a ride on
Google.

Regards
Al
 
A

acb

After a little bit of thinkering I figured out the save. Still have one
problem though; I need to differentiate between a contact entry and a
distribution list entry the line ' If objContact Is
OlItemType.olContactItem Then' which doesn't work is what I would like
to do.

The revised version of the code now stands as follows:

Sub DelUDFld()
Dim olApp As Outlook.Application
Dim objContact As Outlook.ContactItem
Dim objContacts As Outlook.MAPIFolder
Dim objNameSpace As Outlook.NameSpace
Dim objProperty As Outlook.UserProperty
Dim updTakenPlace As Boolean

Set olApp = CreateObject("Outlook.Application")
Set objNameSpace = olApp.GetNamespace("MAPI")
Set objContacts = objNameSpace.GetDefaultFolder(olFolderContacts)
For Each objContact In objContacts.Items
If objContact Is OlItemType.olContactItem Then

updTakenPlace = False
For Each objProperty In objContact.UserProperties
If objProperty.Name <> "LoginName" Then
'MsgBox objProperty.Name
objProperty.Delete
updTakenPlace = True
End If
Next objProperty
Set objProperty = Nothing
If updTakenPlace Then
objContact.Save
End If
End If
Next objContact
Set objContact = Nothing
End Sub


Thanks,
Al
 
S

Sue Mosher [MVP-Outlook]

A "statement" is a line of code (or lines of code joined by the underscore (_) character).

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

Sue Mosher [MVP-Outlook]

Try:

Dim objItem as Object

<snip>

For Each objItem In objContacts.Items
If objItem.Class = olContact Then
Set objContact = objItem

<etc>

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
A

acb

Thanks. Worked as I had expected.

Regards,
Al
Try:

Dim objItem as Object

<snip>

For Each objItem In objContacts.Items
If objItem.Class = olContact Then
Set objContact = objItem

<etc>

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top