• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 521
  • Last Modified:

Update Outlook contact from within Delphi

Hi,

Currently I use following code to find a contact in Outlook:
          ContactGevonden := False;
          for j := 1 to ContactenMap.Items.Count do
          begin
            Contact := ContactenMap.Items.Item(j);
            if (Contact.CustomerID = QRelatiesOutlook.FieldByName('Relatienr').AsString) then
            begin
              ContactGevonden := True;
              Break;
            end;
          end;
          if NOT ContactGevonden then
          begin
            // Aanmaken van een nieuwe contactpersoon.
            Contact := ContactenMap.Items.Add; // (olContactItem); // as ContactItem;
            Toegevoegd := Toegevoegd + 1;
          end;

Open in new window

Is there a quicker way to do this?
0
Stef Merlijn
Asked:
Stef Merlijn
  • 4
  • 3
2 Solutions
 
ThommyCommented:
You can try this...
Accessing Outlook Contacts
0
 
ThommyCommented:
There would hardly be any quicker solution as you already have,  to first check contact list before adding a new outlook contact.

So I do confirm, that you are definitely on the right way with your solution...
0
 
Stef MerlijnDeveloperAuthor Commented:
Thommy, the link you posted won't work on Delphi XE2 as OfficePartner only support Delphi 7 or earlier.

I thought there might be some FIND, SEARCH or LOCATE function that could be used. So you don't have to look at each Outlook contactrecord to find it.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
ThommyCommented:
Yes, seems right, that TOfficePartner component is not developed further since Delphi 7.

If you have Outlook version 2010 and newer, you can try something like this:

function FindOutlookContact(MailAddr: string) : boolean;
var
  OL : OleVariant;
  SearchStr: string;
  TheNameSpace,TheContactFolder,TheContactItem : Variant;
begin
  try
    OL := GetActiveOleObject('Outlook.Application');
  except
    OL := CreateOleObject('Outlook.Application');
  end;

  TheNameSpace := OL.GetNameSpace('MAPI');
  TheContactFolder := vNameSpace.GetDefaultFolder('').Items;
  SearchStr : = '[Email1Address] = ' + '''' +MailAddr + '''';
  TheContactItem := TheContactFolder.Find(SearchStr);
  
   if Assigned(TheContactItem) then
     ...

Open in new window

0
 
Stef MerlijnDeveloperAuthor Commented:
Thank you very much, this looks promissing. But I need be be able to use it in older versions of Office too (from Office XP and up).
0
 
ThommyCommented:
As far as I know, for older Office versions there is no other solution than looping through the contact list...
0
 
Stef MerlijnDeveloperAuthor Commented:
Thank you very much for your answers.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now