PRB: Access Denied Error When You Set a Property in the Global Address List (GAL) (266724)



The information in this article applies to:

  • Collaboration Data Objects (CDO) 1.2
  • Collaboration Data Objects (CDO) 1.21

This article was previously published under Q266724

SYMPTOMS

When you attempt to set a property in the Microsoft Exchange Global Address List (GAL) to an empty string, you may receive the following error message:
You do not have sufficient permission to perform this operation on this object. [Microsoft Exchange Address Book - [E_ACCESSDENIED(80070005)]]

CAUSE

This error message is misleading because it is only displayed when you attempt to set the property to an empty string.

RESOLUTION

To work around this problem, check the new value before you set the property:
if NewNum = "" Then
	objAddressEntry.Fields(myMAPIProperty) = vbEmpty 'Empty in VBScript
Else
	objAddressEntry.Fields(myMAPIProperty) = NewNum
End If
				

MORE INFORMATION

Steps to Reproduce Problem

Run the following code in Microsoft Visual Basic:

NOTE: The code assumes that you have a reference to the Microsoft Collaboration Data Objects (CDO) Library version 1.2 or later within your Visual Basic project.
Dim StrServer 'Exchange Server Name.
DIm StrUser 'User account with permissions to modify global address list.
Dim CdoPR_HOME_TELEPHONE_NUMBER

'Set the Hex value for Home Phone 2.
CdoPR_HOME2_TELEPHONE_NUMBER = &H3A2F001E

'Create the MAPI object.
Set objSession = CreateObject("MAPI.Session")

'Connect to the Exchange Server.
objSession.Logon , , False, False, , True, strServer & vbLf & strUser

'Open the GAL and apply a filter for the current user.
Set objAddrEntries = objSession.AddressLists("Global Address List").AddressEntries
Set objFilter = objAddrEntries.Filter
objFilter.Fields.Add CdoPR_ACCOUNT, StrUser
Set objAddressEntry = objAddrEntries(1)

'The error occurs on this line:
objAddressEntry.Fields(CdoPR_HOME2_TELEPHONE_NUMBER) = ""
				
NOTE: You can substitute the last line of code with any one of the following:
objAddressEntry.Fields(CdoPR_HOME2_TELEPHONE_NUMBER) = vbEmpty
objAddressEntry.Fields(CdoPR_HOME2_TELEPHONE_NUMBER) = Null
objAddressEntry.Fields(CdoPR_HOME2_TELEPHONE_NUMBER) = "90823098"
				

Modification Type:MinorLast Reviewed:3/4/2004
Keywords:kbMsg kbprb KB266724