Microsoft KB Archive/313793

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

Article ID: 313793

Article Last Modified on 5/19/2005

-

APPLIES TO


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

-



This article was previously published under Q313793



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:  Start Microsoft Visual Studio .NET. On the File menu, point to New, and then click Project. Under Project Types, click Visual Basic Projects. Under Templates, click Console Application, and then click OK.

By default, Module1.vb is created. Add a reference to either the Outlook 2002 Object Library or the Outlook 2003 Object Library:  On the Project menu, click Add Reference. 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.</li> 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.</li></ol> </li>  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(&quot;mapi&quot;) Dim oSyncs As Outlook.SyncObjects Dim oSync As Outlook.SyncObject

Try ' Reference SyncObjects. oSyncs = oNS.SyncObjects oSync = oSyncs.Item(&quot;All Accounts&quot;) ' 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 Sub

End Module </li> Press F5 to build and run the program.</li></ol>

<div class="references_section">