Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Look up e-mail recipients from Outlook address book

Posted on 2003-11-19
9
Medium Priority
?
1,054 Views
Last Modified: 2007-12-19
Here is what I need to be able to do.
We use Outlook 98 across the board around here.  If a user is composing an e-mail message and the recipient is something like 'Joe Blow', they can usually just write "Blow, J" or something like that and Outlook will resolve the rest.  It looks up the contact in the global address book and if there is only one match, it replaces "Blow, J" with that contact.  If there is more than one match it prompts the user to pick one.

In my app users can click a button to create a new e-mail message, with the body populated with info from the current record.  I have built in something that will also populate the 'To' field with a list of contacts.  This list is maintained by the users on a diferent form.  Each contact is just a name in plain text and optionally an e-mail address, but in most cases this is not required since it is always an internal contact.  What I do is create a new MAPI.Recipient, assign the e-mail address if applicable, assign its name accordingly, and then call MAPI.Recipient.Resolve to have it resolve to a contact on the outlook message.

What I would like to do is have the resolution happen on the other form where the list is maintained.  i.e., a user enters all or part of a contact name into my text box, clicks OK, and then it would resolve to the correct contact.  I would need to store the full name and e-mail address.  There would be no change to the way my e-mails are sent, it would still just have to take the plain text name and e-mail and assign it to a MAPI.Recipient.  The difference is that the user is able to check if the contact is valid or not when they first save that text.

In other words, I have a (full or partial) name, and I want a proper contact name and e-mail address from the global address book.

I hope this makes sense.  How can it be accomplished?

Thanks.

0
Comment
Question by:pteehan
[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
  • 5
  • 3
9 Comments
 
LVL 9

Expert Comment

by:Dang123
ID: 9782688
0
 
LVL 2

Author Comment

by:pteehan
ID: 9782800
Well, that's a good start...but it doesn't really do what I need, which is basically a function to look up a name query.  Partial name goes in, full name and e-mail address come out.  And sadly I have no time to figure it out for myself, hence the 500 points :)

Also I am hesitant to get into specific application code in case the client changes (at the very least to a new version of Outlook, which might happen soon).  The code I have in place now uses the MAPI interface and ideally I could use that if possible (though if there is no other option we could at least look at it).

I would think the MAPI.Recipient.Resolve function must do what I need somehow.  I just don't know how to use it properly.  

0
 
LVL 9

Accepted Solution

by:
Dang123 earned 1000 total points
ID: 9787360
Perhaps this is what you want. It is a small form that resolves a single name against the Outlook address book. You should be able to something similar on your second form, looping through the names, and save the information as you need.



In a new project add a referenct to Microsoft Outlook Object Library
On the form, add a text box and a command button.
Paste this code into the form.

'----------------------------------------------------
Private Sub Command1_Click()
    Dim OutlookApp As Outlook.Application
    Dim MailItem As Outlook.MailItem
    Dim Recipient As Outlook.Recipient
   
    Set OutlookApp = New Outlook.Application
    Set MailItem = OutlookApp.CreateItem(0)
    Set Recipient = MailItem.Recipients.Add(Text1.Text)
    If Recipient.Resolve Then
        Text1.Text = Recipient.Name
    Else
        MsgBox "There is an invalid recipient"
    End If
   
    Set Recipient = Nothing
    Set MailItem = Nothing
    Set OutlookApp = Nothing
End Sub

0
Technology Partners: 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 2

Author Comment

by:pteehan
ID: 9789378
Great!  Thanks.  Getting very close now.  I could probably use this.

THe only problem is that it is likely to fail a lot (there are a LOT of people at my company and thus a lot of ambiguous names) and there isn't really much they can do.  For example, if they enter John Smith it will always fail, unless I can get them to look up the e-mail address, but that will make it more difficult to use.

When you try and send a message to an ambiguous user in Outlook it pops up a dialog box with a list of possible matches, and it resolves to the one you pick.   Is it possible to launch this dialog if resolve fails and catch the name that the user picks?

0
 
LVL 9

Expert Comment

by:Dang123
ID: 9790842
I'm having trouble finding something useful to put in the else for a failed resolve. I'll keep looking though!

Dang123

0
 
LVL 2

Author Comment

by:pteehan
ID: 9850465
I did some research into the CDO object reference on MSDN and was able to find an example that I could adapt.  I sidestepped the problem of failing resolves by focing them to choose a name from the original address book.  Here is the code for anyone who happens upon this page:

Function Session_AddressBook() As MAPI.Recipient
    On Error GoTo err_Session_AddressBook

    If objSession Is Nothing Then
        'Session_AddressBook = "LOOKUP FAILED"
       ' MsgBox "Must first create MAPI session and logon"
        Exit Function
    End If
    Set objRecipColl = objSession.AddressBook( _
                       Title:="Select Contact", _
                       oneAddress:=True, _
                       forceResolution:=True, _
                       recipLists:=1, _
                       toLabel:="&Recipient") ' appears on button
    ' Note: first parameter ("recipients") not used in this call
    ' recipients:=objInitRecipColl initializes recipients for dialog
'    MsgBox "Name of first recipient = " & objRecipColl.Item(1).Name
    Set Session_AddressBook = objRecipColl.item(1)
    Exit Function

err_Session_AddressBook:
    If (Err = 91) Then ' MAPI dlg-related function that sets an object
        'MsgBox "No recipients selected"
    Else
       ' MsgBox "Unrecoverable Error:" & Err
    End If
    Exit Function
End Function

Dang I appreciate your help even though I eventually found the answer myself.  I do want to reward your efforts but I am reluctant to let go of my 500 points! :)  What should I do.
0
 
LVL 9

Expert Comment

by:Dang123
ID: 9850729
pteehan,
    Nice solution, glad you got your problem worked through. Sorry I couldn't provide more help, something with a higher priority came in a few days later from my boss; you know how that goes.

BTW: You could drop the point value to what ever you feel is appropriate.

Dang123

0
 
LVL 9

Expert Comment

by:Dang123
ID: 9857690
pteehan,
    Thanks!   : )
Dang123
0

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.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

722 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