Solved

Update Outlook contact from within Delphi

Posted on 2013-02-04
7
496 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now