Solved

Update Outlook contact from within Delphi

Posted on 2013-02-04
7
509 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

734 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