Previous | Index | Next 

[PRB] Errors when re-opening modal, default forms that host an ActiveX control

Consider the following scenario:

  1. You have a form that hosts one or more ActiveX controls
  2. You display the form modally (e.g. Form1.Show 1)
  3. You access the form using the default instance rather then creating a fresh instance of the form.

In these circumstances, you can experience runtime errors when you close and then re-open the form.

The simplest workaround for this problem is using a fresh new form:

     ' old code
     Form1.Show vbModal
     
     ' new code
     Dim frm As New Form1
     frm.Show vbModal

You can even use a variable named after the form class to “shadow” the default form instance:

     Dim Form1 As New Form1
     Form1.Show vbModal

This latter solution can be easily implemented by means of a single InsertStatement pragma:

     '## InsertStatement Dim Form1 As New Form1
     Form1.Show vbModal

If you are forced to use the default form instance you must adopt a different workaround: you should set the AutoDisposeModalForm static property to False before showing the form and invoke the ResetVariables protected method after showing the form

     '## InsertStatement VB6Form.AutoDisposeModalForm = False
     Form1.Show vbModal
     '## InsertStatement MyBase.ResetVariables()

 

Previous | Index | Next