How to use the Microsoft Outlook Object Library to force a Send/Receive action by using Visual Basic .NET

This article was previously published under Q313793
This article has been archived. It is offered "as is" and will no longer be updated.
SUMMARY
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.
MORE INFORMATION
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.OutlookModule 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        Try            ' Reference SyncObjects.            oSyncs = oNS.SyncObjects            oSync = oSyncs.Item("All Accounts")            ' Send and receive.            oSync.Start()        Catch ex As Exception            Console.WriteLine(ex.Message)        End Try        ' Clean up.        oSync = Nothing        oSyncs = Nothing        oNS = Nothing        oApp = Nothing    End SubEnd Module
  7. Press F5 to build and run the program.
REFERENCES
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
Outsol Outsol2002
Properties

Article ID: 313793 - Last Review: 12/07/2015 08:16:05 - Revision: 2.2

Microsoft Office Outlook 2003, Microsoft Outlook 2002 Standard Edition, Microsoft Visual Basic .NET 2003 Standard Edition, Microsoft Visual Basic .NET 2002 Standard Edition

  • kbnosurvey kbarchive kbhowtomaster KB313793
Feedback