Consider the following scenario:
- You have a form that hosts one or more ActiveX controls
- You display the form modally (e.g. Form1.Show 1)
- 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
' new code
Dim frm As New Form1
You can even use a variable named after the form class to “shadow” the default form instance:
Dim Form1 As New Form1
This latter solution can be easily implemented by means of a single InsertStatement pragma:
'## InsertStatement Dim Form1 As New Form1
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
'## InsertStatement MyBase.ResetVariables()