locked
VB and Outlook Contacts RRS feed

  • Question

  • I am trying to import, or copy, the contacts from Outlook into a SQL database using Visual Basic 2005 Express.  I do know how to do it using Access VB, but I want it to look professional.  Thanks all.

    Fred.

    Wednesday, September 19, 2007 11:27 PM

Answers

  • Hi Fred,

     

    Based on your post, you need to get the contact items from the Outlook and import the contact items into a SQL database. You can take the two steps to achieve this.

     

    1.  Get all contact items from the outlook. Here is the code snippet to get all contact items from the outlook.

    Code Snippet

    Dim outlookApp As Microsoft.Office.Interop.Outlook._Application = _

    New Microsoft.Office.Interop.Outlook.Application()

    Dim cntctFolder As Microsoft.Office.Interop.Outlook.MAPIFolder = _

    DirectCast(outlookApp.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderContacts), _

    Microsoft.Office.Interop.Outlook.MAPIFolder)

    MessageBox.Show(cntctFolder.Items.Count.ToString)

    Dim c As Microsoft.Office.Interop.Outlook.ContactItem

    Dim objItems As Microsoft.Office.Interop.Outlook.Items

    objItems = cntctFolder.Items

    Dim iNumTasks As Integer = objItems.Count

    For i As Integer = 1 To iNumTasks

    c = objItems(i)

    MessageBox.Show(c.FullName.ToString())

    Next

     

    I would like to recommend these articles about the outlook automation to you.

    2.  You need to create the Sql server database. Then you can use the SqlCommand to insert the contact items into the database. Please see the following article:

     

    Best regards,

    Riquel.

     

    Monday, September 24, 2007 9:57 AM
    Moderator

All replies

  • You forgot to ask a question.
    Sunday, September 23, 2007 2:36 PM
    Moderator
  • Sorry, my question is how do I import the contact list into a SQL database using VB 2005 express.

    Thanks
    Sunday, September 23, 2007 10:41 PM
  • Hi Fred,

     

    Based on your post, you need to get the contact items from the Outlook and import the contact items into a SQL database. You can take the two steps to achieve this.

     

    1.  Get all contact items from the outlook. Here is the code snippet to get all contact items from the outlook.

    Code Snippet

    Dim outlookApp As Microsoft.Office.Interop.Outlook._Application = _

    New Microsoft.Office.Interop.Outlook.Application()

    Dim cntctFolder As Microsoft.Office.Interop.Outlook.MAPIFolder = _

    DirectCast(outlookApp.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderContacts), _

    Microsoft.Office.Interop.Outlook.MAPIFolder)

    MessageBox.Show(cntctFolder.Items.Count.ToString)

    Dim c As Microsoft.Office.Interop.Outlook.ContactItem

    Dim objItems As Microsoft.Office.Interop.Outlook.Items

    objItems = cntctFolder.Items

    Dim iNumTasks As Integer = objItems.Count

    For i As Integer = 1 To iNumTasks

    c = objItems(i)

    MessageBox.Show(c.FullName.ToString())

    Next

     

    I would like to recommend these articles about the outlook automation to you.

    2.  You need to create the Sql server database. Then you can use the SqlCommand to insert the contact items into the database. Please see the following article:

     

    Best regards,

    Riquel.

     

    Monday, September 24, 2007 9:57 AM
    Moderator