Microsoft KB Archive/314821

= FIX: Exception Error When You Use For...Each Loop to Iterate Through Outlook Folder Collection =

Article ID: 314821

Article Last Modified on 2/22/2002

-

APPLIES TO


 * Microsoft Visual FoxPro 7.0 Professional Edition

-



This article was previously published under Q314821



SYMPTOMS
When you use a Visual FoxPro (VFP) For...Each loop to automatically iterate through a Microsoft Outlook folder collection, the following error message appears and VFP closes.

Fatal error: Exception code=C0000005



RESOLUTION
To resolve this problem, obtain the latest service pack for Visual FoxPro for Windows 7.0. For additional information, click the following article number to view the article in the Microsoft Knowledge Base:

316964 How to Obtain the Latest Visual FoxPro for Windows 7.0 Service Pack



STATUS
Microsoft has confirmed that this is a problem in Microsoft Visual FoxPro for Windows 7.0. This problem was first corrected in Visual FoxPro for Windows 7.0 Service Pack 1.



Steps to Reproduce Behavior
Save the following code in a program (.prg) file and then run the program. Note that you must have Microsoft Outlook 2000 or later installed on your computer. CLEAR LOCAL loOutlook as Outlook.Application, ; loNameSpace as Object, ; loFolder as Object, ; loSelFolder as Object, ; loSubFolder as Object, ; loMsgs as Object

loOutlook = CREATEOBJECT('Outlook.Application') loNameSpace = loOutlook.GetNameSpace(&quot;MAPI&quot;) loFolder = NULL loSelFolder = NULL loSubFolder = NULL loMsgs = NULL

FOR EACH loFolder IN loNameSpace.Folders FOR EACH loSubFolder IN loFolder.Folders IF ALLTRIM(loSubFolder.NAME) == &quot;Inbox&quot; loSelFolder = loSubFolder EXIT ENDIF ENDFOR IF !ISNULL(loSelFolder) EXIT ENDIF ENDFOR

IF VARTYPE(loSelFolder) == &quot;O&quot; loMsgs = loSelFolder.Items ? &quot;You have &quot; + TRANSFORM(loMsgs.Count) + ; &quot; message in your Outlook InBox&quot; ENDIF

loOutlook.Quit RELEASE ALL After you install Visual FoxPro 7.0 Service Pack 1, the program runs successfully and the number of items in your Outlook Inbox prints to the screen.

Additional query words: kbVFP700sp1fix

Keywords: kbbug kbfix kbautomation KB314821

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.