Microsoft small business knowledge base

Article ID: 313793 - Last Review: May 19, 2005 - Revision: 2.2

This article was previously published under Q313793


This article describes how to use the Microsoft Outlook 2002 Object Library or the Microsoft Office Outlook 2003 Object Library to force a Send/Receive action by using Microsoft Visual Basic .NET.


To use the Outlook 2002 Object Library or the Outlook 2003 Object Library to force a Send/Receive action in a Visual Basic .NET project, follow these steps:
  1. Start Microsoft Visual Studio .NET.
  2. On the File menu, point to New, and then click Project.
  3. Under Project Types, click Visual Basic Projects.
  4. Under Templates, click Console Application, and then click OK.

    By default, Module1.vb is created.
  5. Add a reference to either the Outlook 2002 Object Library or the Outlook 2003 Object Library:
    1. On the Project menu, click Add Reference.
    2. On the COM tab, click Microsoft Outlook 11.0 Object Library if you are using Outlook 2003, or click Microsoft Outlook 10.0 Object Library if you are using Outlook 2002, and then click Select.
    3. In the Add References dialog box, click OK to accept your selections. If you receive a prompt to generate wrappers for the libraries that you selected, click Yes.
  6. In the code window, replace all the code with:
    'TO DO: If you use the Microsoft Outlook 11.0 Object Library, uncomment the following line.
    'Imports Outlook = Microsoft.Office.Interop.Outlook
    Module Module1
        Sub Main()
            ' Create an Outlook application.
            Dim oApp As Outlook._Application = New Outlook.Application
            ' Create the name space.
            Dim oNS As Outlook._NameSpace = oApp.GetNamespace("mapi")
            Dim oSyncs As Outlook.SyncObjects
            Dim oSync As Outlook.SyncObject
                ' Reference SyncObjects.
                oSyncs = oNS.SyncObjects
                oSync = oSyncs.Item("All Accounts")
                ' Send and receive.
            Catch ex As Exception
            End Try
            ' Clean up.
            oSync = Nothing
            oSyncs = Nothing
            oNS = Nothing
            oApp = Nothing
        End Sub
    End Module
  7. Press F5 to build and run the program.


For additional information about available resources and answers to frequently asked questions about Microsoft Outlook solutions, click the following article number to view the article in the Microsoft Knowledge Base:
287530  ( ) OL2002: Questions about custom forms and Outlook solutions

  • Microsoft Office Outlook 2003
  • Microsoft Outlook 2002 Standard Edition
  • Microsoft Visual Basic .NET 2003 Standard Edition
  • Microsoft Visual Basic .NET 2002 Standard Edition
kbhowtomaster KB313793
Additional support options
Ask The Microsoft Small Business Support Community
Contact Microsoft Small Business Support
Find Microsoft Small Business Support Certified Partner
Find a Microsoft Store For In-Person Small Business Support