Microsoft KB Archive/823995

= PRB: The Open Event Fires More Than One Time When You Open a Managed Code Extension for a Microsoft Office Word 2003 Document =

Article ID: 823995

Article Last Modified on 5/16/2007

-

APPLIES TO


 * Microsoft Office Word 2003
 * Microsoft Visual Studio Tools for the Microsoft Office System version 2003

-





SYMPTOMS
When you open a managed code extension for a Microsoft Office Word 2003 document, the Open event fires more than one time. This behavior might give you the impression that Word has stopped responding.



CAUSE
This problem occurs if all of the following conditions are met: :  Your Microsoft Visual Basic project Option Strict setting is set to Off.

-and- You use one of the following methods in the Open event handler of the document:

 RecentFile::Add Windows::CompareSideBySideWith XMLNamespace::AttachToDocument

-and- You pass the ThisDocument variable as a parameter to one of the aforementioned methods.</li></ul>

When you call one of the aforementioned methods, the document reference is passed as a parameter. When the document reference is passed as a parameter to a method that is used in the Open event, the managed code extension calls Word to sink additional objects to its connection point list. This behavior causes the Open event to fire more than one time.

<div class="resolution_section">

RESOLUTION
To resolve this problem, cast the ThisDocument variable to an Object data type variable, and then pass the Object data type variable. If the Option Strict project setting is turned on, you must cast the document parameter to an Object data type to avoid a compilation error.

<div class="moreinformation_section">

Steps to Reproduce the Behavior
<ol> Start Microsoft Visual Studio .NET 2003.</li> On the File menu, point to New, and then click Project.

The New Project dialog box appears.</li> In the Project Types list, expand Microsoft Office System Projects, and then click Visual Basic Projects.</li> In the Templates list, click Word Document, and then click OK.

The Microsoft Office Project Wizard appears.</li> In the Microsoft Office Project Wizard, click Finish.</li>  Add the following code to the ThisDocument_Open event handler: Dim result As DialogResult = MessageBox.Show( _   &quot;Continue?&quot;, &quot;&quot;, MessageBoxButtons.YesNo) If result = DialogResult.Yes Then ThisApplication.RecentFiles.Add(ThisDocument) End If </li> Press the F5 key to build the solution and to run the solution.

The document appears in Word. You are prompted to continue.</li> Click Yes to continue.

You are prompted to continue again (the Open event fired again).</li> Click No.</li> Quit Word.</li></ol>

To correct the problem, replace the code in the ThisDocument_Open event handler with the following code: Dim result As DialogResult = MessageBox.Show( _   &quot;Continue?&quot;, &quot;&quot;, MessageBoxButtons.YesNo) If result = DialogResult.Yes Then ThisApplication.RecentFiles.Add(CType(ThisDocument, Object)) End If

<div class="references_section">