HOWTO: Using OLE Automation to Display Outlook from VFP

Last reviewed: September 11, 1997
Article ID: Q173582
The information in this article applies to:
  • Pro Edition of Microsoft Visual FoxPro for Windows, versions 3.0, 3.0b
  • Microsoft Visual Studio, versions 97, 97sp1, 97sp2

SUMMARY

You may want to display Microsoft Outlook from Visual FoxPro to allow users to read or send messages or to open other folders in Outlook. This article demonstrates how to do this.

MORE INFORMATION

The Outlook object provides the functionality to control data stored in the Outlook folders, but there is limited functionality to manipulate Outlook itself. Since you probably want to interact with the data stored in Outlook, you need to create a reference to the Messaging Application Programming Interface (MAPI) folders where Outlook stores all of its information. Do this by setting a variable to the "Namespace" object.

The following code creates and displays an instance of Outlook. Visual FoxPro for Windows pauses execution as long as the user has the Outlook application on top using the GetActivewindow API function call. If the Visual FoxPro application window is brought on top, then the code forces Outlook to close:

   oOutlookObj = CREATEOBJECT("Outlook.Application")
   oNamespace = oOutlookObj.GetNamespace("MAPI")
   oFolder = oNamespace.GetDefaultfolder(6)   && See below for other values
   oFolder.Display

   * Code to pause FoxPro while Outlook window is on top
   IF NOT 'FOXTOOLS' $ SET('LIBRARY')
      SET LIBRARY TO SYS(2004)+"FoxTools"
   ENDIF
   FoxWind = MAINHWND()
   GetActive=RegFn('GetActiveWindow','','I') && Determine if FoxPro is
                                             && on top
   DO WHILE .T.    && Keep looping until the ActiveWindow = FoxWind
      IF FoxWind = CallFn(GetActive)
         EXIT
      ENDIF
   ENDDO
   SET LIBRARY TO

   oOutlookObj.Quit

The GetDefaultfolder method has several values that open different folders in Outlook. The list below provides the default folder values.

   Folder Name      Value
   ----------------------
   Deleted Items      3
   Outbox             4
   Sent Items         5
   Inbox              6
   Calendar           9
   Contacts          10
   Journal           11
   Notes             12
   Tasks             13

REFERENCES

Microsoft Outlook Visual Basic Help

For more information about pausing FoxPro program execution, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q131634
   TITLE     : HOWTO: Pausing Program Execution while RUN /N Command is
               Running

(c) Microsoft Corporation 1997, All Rights Reserved. Contributions by Dean Christopher, Microsoft Corporation
Keywords          : FxinteropOle FxprgGeneral vfoxwin
Technology        : kbole
Version           : WINDOWS:3.0,3.0b; WINNT:97,97sp1,97sp2
Platform          : WINDOWS winnt
Issue type        : kbhowto


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 11, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.