Solved

Update Outlook contact from within Delphi

Posted on 2013-02-04
7
500 Views
Last Modified: 2013-02-06
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
Comment
Question by:Delphiwizard
  • 4
  • 3
7 Comments
 
LVL 19

Expert Comment

by:Thommy
ID: 38850933
You can try this...
Accessing Outlook Contacts
0
 
LVL 19

Expert Comment

by:Thommy
ID: 38851042
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
 

Author Comment

by:Delphiwizard
ID: 38851431
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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
LVL 19

Accepted Solution

by:
Thommy earned 500 total points
ID: 38852460
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
 

Author Comment

by:Delphiwizard
ID: 38854758
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
 
LVL 19

Assisted Solution

by:Thommy
Thommy earned 500 total points
ID: 38860036
As far as I know, for older Office versions there is no other solution than looping through the contact list...
0
 

Author Closing Comment

by:Delphiwizard
ID: 38860403
Thank you very much for your answers.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…

822 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question