Microsoft KB Archive/237286

= BUG: Event Does Not Fire in the IDE When Raised from Inside a Compiled Modal Form =

Article ID: 237286

Article Last Modified on 5/12/2003

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q237286



SYMPTOMS
When using compiled components with events, and the event is triggered from a modal form inside the component, the event is not received by the client application when it is run from the Visual Basic Design Environment (IDE). This problem does not occur when both components have been compiled.



RESOLUTION
Display the form that triggers the event non-modally to avoid the problem when testing the application in the IDE.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce Behavior
 Start a new Visual Basic ActiveX DLL project. Class1 is created by default. On the Project menu, click Project1 Properties. In the Project Properties dialog box, set the Project Name field to MyEventsDll. Click OK.  Add the following code to the General Declarations section of Class1: Option Explicit

Public Event DoSomething

Public Sub FireEvent RaiseEvent DoSomething End Sub

Public Sub ShowForm(ByVal ShowType As Long) Form1.SetEventObject Me  If ShowType = vbModeless Then Form1.Caption = "Non-Modal" Form1.Show Else Form1.Caption = "Modal" Form1.Show vbModal End If End Sub  On the Project menu, click Add Form to add a new form to the project. Form1 is created by default. Add a CommandButton to Form1.  Add the following code to the General Declarations section of Form1: Option Explicit

Dim EventObject As Class1

Public Sub SetEventObject(objNew As Class1) Set EventObject = objNew End Sub

Private Sub Command1_Click EventObject.FireEvent End Sub

Private Sub Form_Load Command1.Caption = "Fire Event" End Sub </li> Save the project and compile it.</li> On the File menu, click New Project. Create a new Visual Basic Standard EXE project. Form1 is created by default.</li> Change the name of Form1 to frmTest.</li> On the Project menu, click References. Add a reference by checking MyEventsDll and clicking OK.</li> Add two CommandButtons to frmTest.</li>  Add the following code to the General Declarations section of frmTest: Option Explicit

Dim WithEvents MyObj As MyEventsDll.Class1

Private Sub Command1_Click MyObj.ShowForm vbModal ' Show Form Modal End Sub

Private Sub Command2_Click MyObj.ShowForm vbModeless ' Show Form Non-Modal End Sub

Private Sub Form_Load Set MyObj = New MyEventsDll.Class1 Command1.Caption = "Show Form Modal" Command2.Caption = "Show Form Non-Modal" End Sub

Private Sub MyObj_DoSomething MsgBox "Received event from DLL" End Sub </li> Save the project.</li> Press the F5 key to run the project in the IDE.</li> Click the Show Form Non-Modal button to display the form from the DLL as non-modal. Click the Fire Event button. A message box displaying the text "Received event from DLL" should be displayed, confirming that the event fired from inside the DLL reached the client application.</li> Close the non-modal form.</li> Click the Show Form Modal button to display the form from the DLL as modal. Click the Fire Event button and observe that the message box is not displayed. This demonstrates that the event that was fired from the modal form was not received by the client.</li> On the Project menu, click Make Project1.exe to compile the client.</li> Run Project1.exe and repeat the steps above. The message box should display whether the form in the DLL is shown modally or non-modally.</li></ol>

<div class="references_section">