Microsoft KB Archive/143048

= BUG: Form Unload in Any DBGrid Event Ends Visual Basic =

Article ID: 143048

Article Last Modified on 12/3/2003

-

APPLIES TO


 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 16-bit Enterprise Edition
 * Microsoft Visual Basic 4.0 32-Bit Enterprise Edition

-



This article was previously published under Q143048



SYMPTOMS
Unloading a form with a DBGrid control by using the Unload statement in the any event of the DBGrid control causes an application error that ends the Visual Basic program. The following are ways to work around this issue:


 * Set the form to nothing prior to unloading the form.

-or-
 * Unload the form in an event other than a DBGrid event.



STATUS
Microsoft has confirmed this to be an issue in the Microsoft products listed at the beginning of this article. Microsoft is researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.



MORE INFORMATION
The following is an example to reproduce this behavior. Two forms are used:


 * The first form has a command button that shows the second form.
 * The second form contains the DBGrid control. The click event of the DBGrid control unloads the second form. Run the program and click the command button to show the second form. Click the DBGrid control in the second form and the application error occurs.

Steps to Reproduce Behavior
 Start Visual Basic 4.0 or if it is already running, click New Project on the File menu. Add a command button to the Form1 form.  Copy the following code sample to the Form1 code window: Option Explicit

Private Sub Command1_Click 'Show Form2 Form2.Show End Sub

 On the Insert menu, click Form to insert a second form into the project.  Add a DBGrid control to the Form2 form and copy the following code sample to the Form2 code window: Option Explicit

Private Sub DBGrid1_Click 'Remove the comment marks from the next two lines 'to work around the bug. 'Form2.Hide 'Set Form2 = Nothing Unload Form2 End Sub

 On the Run menu, click Start, or press the F5 key to start the program. Click the Command1 command button to display the second form. Click on the DBGrid control in the second form. An application error occurs with the following message and Visual Basic ends:</li></ol>

<pre class="fixed_text">  32-bit Visual Basic 4.0:

Windows NT-An application error has occurred and an application error log is being generated. VB32.exe, Exception: access violation (0xc0000005), Address: 0x022a00b8.

Windows 95-VB32 caused and invalid page fault in module at                0000:00000015.

16-bit edition of Visual Basic 4.0:

All Operating Systems - VB caused a general protection fault in                             module DBGrid16.OCX at 0003:0000fb7f.

Additional query words: 4.00 vb4win vb4all

Keywords: kbbug KB143048

-

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

© Microsoft Corporation. All rights reserved.