Board index » delphi » Outlook Contact Field - How to test for null

Outlook Contact Field - How to test for null


2004-05-04 08:00:57 AM
delphi226
if varType(MSOutLook) <>varNull then
MSOutLook := CreateOLEObject('Outlook.Application');
myFolder := MSOutLook.GetNamespace('MAPI');
MyContacts := myFolder.GetDefaultFolder(olFolderContacts);
myItems := MyContacts.Items;
How do I test for non assignment of a field ie
VarType(myItems.Item(i).LastName) = VarNull or
myItems.Item(i).LastName = null
The only way I can do this successfully is with an iteration of the
ItemProperties property
myItem := myItems.Item(i);
for j := 0 to myItem.ItemProperties.count - 1 do
begin
if myItem.ItemProperties.Item[j].Name = 'LastName' then
FoundLastName := True;
end;
Is there a find method that works
MyUserProp := myItem.ItemProperties.Item.Find('[Name] = "LastName"');
or some other way to test for the field?
TIA
Peter
 
 

Re:Outlook Contact Field - How to test for null

Peter, use the VarIsNull or VarIsEmpty functions:
if VarIsNull(myItems.Item(i).LastName) or
VarIsEmpty(myItems.Item(i).LastName) then
<...>
"Peter Batten" <XXXX@XXXXX.COM>writes
Quote
if varType(MSOutLook) <>varNull then
MSOutLook := CreateOLEObject('Outlook.Application');
myFolder := MSOutLook.GetNamespace('MAPI');
MyContacts := myFolder.GetDefaultFolder(olFolderContacts);
myItems := MyContacts.Items;

How do I test for non assignment of a field ie
VarType(myItems.Item(i).LastName) = VarNull or
myItems.Item(i).LastName = null

The only way I can do this successfully is with an iteration of the
ItemProperties property

myItem := myItems.Item(i);
for j := 0 to myItem.ItemProperties.count - 1 do
begin
if myItem.ItemProperties.Item[j].Name = 'LastName' then
FoundLastName := True;
end;

Is there a find method that works
MyUserProp := myItem.ItemProperties.Item.Find('[Name] = "LastName"');

or some other way to test for the field?

TIA

Peter



 

Re:Outlook Contact Field - How to test for null

Thanks Mike but this still raises a "Method 'LastName' is not supported by
Automation Object" error for a blank contact.
Peter
"Mike Shkolnik" <XXXX@XXXXX.COM>writes
Quote
Peter, use the VarIsNull or VarIsEmpty functions:

if VarIsNull(myItems.Item(i).LastName) or
VarIsEmpty(myItems.Item(i).LastName) then
<...>

--
With best regards, Mike Shkolnik
E-mail: XXXX@XXXXX.COM
WEB: www.scalabium.com

"Peter Batten" <XXXX@XXXXX.COM>writes
news:XXXX@XXXXX.COM...
>if varType(MSOutLook) <>varNull then
>MSOutLook := CreateOLEObject('Outlook.Application');
>myFolder := MSOutLook.GetNamespace('MAPI');
>MyContacts := myFolder.GetDefaultFolder(olFolderContacts);
>myItems := MyContacts.Items;
>
>How do I test for non assignment of a field ie
>VarType(myItems.Item(i).LastName) = VarNull or
>myItems.Item(i).LastName = null
>
>The only way I can do this successfully is with an iteration of the
>ItemProperties property
>
>myItem := myItems.Item(i);
>for j := 0 to myItem.ItemProperties.count - 1 do
>begin
>if myItem.ItemProperties.Item[j].Name = 'LastName'
then
>FoundLastName := True;
>end;
>
>Is there a find method that works
>MyUserProp := myItem.ItemProperties.Item.Find('[Name] =
"LastName"');
>
>or some other way to test for the field?
>
>TIA
>
>Peter
>
>
>


 

Re:Outlook Contact Field - How to test for null

Are you sure you have a ContactItem and not something else (such as
DistListItem)?
Even if LastName is not set on a contact, OOM will still return an empty
string, so testing for the variant type is useless.
Check the value of the Class property (exposed by all OOM objects) - it is
40 for ContactItem, 69 for DistListItem, etc.
Dmitry Streblechenko (MVP)
www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
"Peter Batten" <XXXX@XXXXX.COM>writes
Quote
Thanks Mike but this still raises a "Method 'LastName' is not supported by
Automation Object" error for a blank contact.

Peter

"Mike Shkolnik" <XXXX@XXXXX.COM>writes
news:XXXX@XXXXX.COM...
>Peter, use the VarIsNull or VarIsEmpty functions:
>
>if VarIsNull(myItems.Item(i).LastName) or
>VarIsEmpty(myItems.Item(i).LastName) then
><...>
>
>--
>With best regards, Mike Shkolnik
>E-mail: XXXX@XXXXX.COM
>WEB: www.scalabium.com
>
>"Peter Batten" <XXXX@XXXXX.COM>writes
>news:XXXX@XXXXX.COM...
>>if varType(MSOutLook) <>varNull then
>>MSOutLook := CreateOLEObject('Outlook.Application');
>>myFolder := MSOutLook.GetNamespace('MAPI');
>>MyContacts := myFolder.GetDefaultFolder(olFolderContacts);
>>myItems := MyContacts.Items;
>>
>>How do I test for non assignment of a field ie
>>VarType(myItems.Item(i).LastName) = VarNull or
>>myItems.Item(i).LastName = null
>>
>>The only way I can do this successfully is with an iteration of the
>>ItemProperties property
>>
>>myItem := myItems.Item(i);
>>for j := 0 to myItem.ItemProperties.count - 1 do
>>begin
>>if myItem.ItemProperties.Item[j].Name = 'LastName'
then
>>FoundLastName := True;
>>end;
>>
>>Is there a find method that works
>>MyUserProp := myItem.ItemProperties.Item.Find('[Name] =
"LastName"');
>>
>>or some other way to test for the field?
>>
>>TIA
>>
>>Peter
>>
>>
>>
>
>