Solved

Update Outlook contact from within Delphi

Posted on 2013-02-04
7
510 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses
Course of the Month5 days, 16 hours left to enroll

626 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