Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,

So I have been Google-ling for round about a day now, and I just don't know how to accomplish this task.

Here is the Scenario, I have two text field boxes - FIRSTNAME and LASTNAME which I type a first and last name into, and then the Global Address Book is checked, I then am hoping for 1 of 3 things.

1. That name will be checked to see if it is in the address book, if it is something happens.

2. A drop down list with all available names that match that is show and I can select that in doing so will then replace the names I typed with the outlook first and last name.

3. The actual Address book window opens where I can search for a name, and then clicking on it will populate the first and last names of the two text boxes.

Any help on this would be greatly appreciated.

I did look at some MS info, and the closes thing I could get is below the issue is that it gives an error when trying to search which I don't understand.

I have Referenced Microsoft Office 14.0 Object Library, and Microsoft Outlook 14.0 Object Library.

The Error that shows up is:
A first chance exception of type 'System.NullReferenceException' occurred in ConsoleApplication1.exe

VB.NET
Imports Microsoft.Office.Interop
Imports System.Reflection

Module Module1

    Sub Main()
        ' Create Outlook application.
        Dim oApp As Outlook.Application = New Outlook.Application()

        ' Get NameSpace and Logon.
        Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi")
        oNS.Logon("Outlook", Missing.Value, False, True) ' TODO:

        ' Get the first contact from the Contacts folder.
        Dim cContacts As Outlook.MAPIFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)
        Dim oItems As Outlook.Items = cContacts.Items

        Dim oCt As Outlook.ContactItem

        Try

            oCt = oItems.Find("[Last Name] = 'stenzel'")

            ' Display some common properties.
            Console.WriteLine(oCt.FullName)
            Console.WriteLine(oCt.Title)
            Console.WriteLine(oCt.Birthday)
            Console.WriteLine(oCt.CompanyName)
            Console.WriteLine(oCt.Department)
            Console.WriteLine(oCt.Body)
            Console.WriteLine(oCt.FileAs)
            Console.WriteLine(oCt.Email1Address)
            Console.WriteLine(oCt.BusinessHomePage)
            Console.WriteLine(oCt.MailingAddress)
            Console.WriteLine(oCt.BusinessAddress)
            Console.WriteLine(oCt.OfficeLocation)
            Console.WriteLine(oCt.Subject)
            Console.WriteLine(oCt.JobTitle)

        Catch

            Console.WriteLine("an error occurred")

        Finally

            ' Display
            'oCt.Display(True)

            ' Log off.
            oNS.Logoff()

            ' Clean up.
            oApp = Nothing
            oNS = Nothing
            oItems = Nothing
            oCt = Nothing

        End Try
    End Sub

End Module
Posted
Updated 1-Oct-13 1:50am
v3
Comments
Thomas Barbare 1-Oct-13 4:59am    
What error ?
Seth C. Stenzel 1-Oct-13 7:51am    
I have Updated the Original question will full code, and the error. Thanks!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900