Solved

Import contact from Microsoft Outlook in .net project

Posted on 2011-09-11
8
240 Views
Last Modified: 2012-05-12
Hello all,

I was feeding a combo box from an access dbase with this code:

 Dim sSQL3 As String
        Dim oConnect3 As ADODB.Connection
        oConnect3 = New ADODB.Connection
        Dim oRST3 As ADODB.Recordset
        oRST3 = New ADODB.Recordset


        sSQL3 = "SELECT DISTINCT[Name]FROM [Clients]'"

        oConnect3.Open("Provider=Microsoft.ACE.OLEDB.12.0;" & _
        "Data Source=" & Form4.base_de_donnee.Text)

        Me.client.Items.Add("")
        oRST3.Open(sSQL3, oConnect3)

        If Not oRST3.EOF Then
            oRST3.MoveFirst()
            Do Until oRST3.EOF
                Me.client.Items.Add(oRST3("Name").Value)
                oRST3.MoveNext()
            Loop

        End If
        Exit Sub
MyErrHandler:
        MsgBox("Connectez-vous sur votre base de données la plus à jour.", _
        vbCritical, _
        "Connection à la basse de donnée Access")
        Me.Close()
        Form4.Show()

Open in new window


But now, i would like to know if i can feed it from my contact list from Outlook, instead of always exporting it in access?

This was to feed my combo box but after, i was having a button to put out the rest of the information from that contact into diffrent text box like this:

Dim sSQL1 As String
        Dim oRST1 As ADODB.Recordset
        oRST1 = New ADODB.Recordset
        Dim oConnect1 As ADODB.Connection
        oConnect1 = New ADODB.Connection


        oConnect1.Open("Provider=Microsoft.ACE.OLEDB.12.0;" & _
       "Data Source=" & Form4.base_de_donnee.Text)


        sSQL1 _
                = " SELECT [Name],[Phone],[Email]" _
                & " FROM [Clients]" _
                & " WHERE Name = '" & client.Text & "'"

        oRST1.Open(sSQL1, oConnect1)

        If oRST1.BOF = False Then

            If Not String.IsNullOrEmpty("Name") Then
                oRST1.Filter = "Name = '" & client.Text & "'"

                'Phone
                telephone.Text = oRST1.Fields.Item(1).Value.ToString

                'Email
                courriel.Text = oRST1.Fields.Item(2).Value.ToString

            End If
        End If

Open in new window


Thanks again for your help.
0
Comment
Question by:Wilder1626
  • 4
  • 3
8 Comments
 
LVL 22

Expert Comment

by:plusone3055
ID: 36520328
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 36520339
Hello plusone3055

thanks but is that C++? not .net?

i have also found this: Microsoft Outlook Integration with C#.NET

but i dont use C++.

0
 
LVL 11

Author Comment

by:Wilder1626
ID: 36520396
I have found this code but it only open the first outlook contact, directly in Outlook.

I want to populate my combobox or could be a list box and see all my contact.

 ' 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.GetFirst()


            ' 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)

            ListView1 = oCt.FullName.ToString
            ' Log off.
            oNS.Logoff()

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

        End Try

Open in new window

0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 36526307
After this


Dim oItems As Outlook.Items = cContacts.Items

        Dim oCt As Outlook.ContactItem


try this

For Each oCt in oItems
     Console.Writeline(oCt.FullName)
     'OR
     Combobox1.Items.Add(oCt.FullName)
Next
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 11

Author Comment

by:Wilder1626
ID: 36526447
Oh perfect for :

For Each oCt in oItems
     Console.Writeline(oCt.FullName)
     'OR
     Combobox1.Items.Add(oCt.FullName)
Next

Open in new window


Now i just need to fix the second part.

If   Combobox1.Items =  ? then
courriel.value = oCt.Email1Address

but i cant make it work.



0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36532037
Not sure what the below is expected to do. Can you explain?


If   Combobox1.Items =  ? then
courriel.value = oCt.Email1Address
0
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 36532452
Well that part was just to show what i was trying to do.


Now, it works great.
Thanks for your help.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36532525
Glad to help :-)
0

Featured Post

Highfive Gives IT Their Time Back

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 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

8 Experts available now in Live!

Get 1:1 Help Now