How to use OLE automation to display Microsoft Outlook from Visual FoxPro (173582)



The information in this article applies to:

  • Microsoft Visual FoxPro for Windows 3.0
  • Microsoft Visual FoxPro for Windows 3.0b
  • Microsoft Visual FoxPro for Windows 6.0
  • Microsoft Visual FoxPro for Windows 7.0
  • Microsoft Visual FoxPro 8.0
  • Microsoft Visual FoxPro 9.0 Professional Edition

This article was previously published under Q173582

SUMMARY

You may want to display Microsoft Outlook from Microsoft Visual FoxPro to allow users to read or to send messages or to open other folders in Outlook. This article describes 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

Modification Type:MajorLast Reviewed:2/28/2005
Keywords:kbhowto KB173582 kbAudDeveloper