Microsoft KB Archive/142839

= Unloading Form from Within DBGrid Event Causes GPF =

Article ID: 142839

Article Last Modified on 12/9/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 Q142839



SYMPTOMS
When unloading a form from within an event of a Data Bound Grid control a General Protection fault will occur in VB.EXE or an Exception fault will occur in VB32.EXE.



CAUSE
The cause of the problem is that the unload event is destroying the recordset object of the data control. When the DBGrid gets control back the recordset pointer is no longer valid.



STATUS
Microsoft has confirmed this to be a problem in Visual Basic version 4.0. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.



WORKAROUND
To work around this problem, add a timer control to the form and allow the "Unload Me" command to happen here rather than in the DBGrid control. Here is a step-by-step example to correct the problem:

 Add a timer control to the form. Set its Enabled property to False and its Interval property to 5.  In the timer event of the timer control add 2 lines of code: Timer1.Enabled = False Unload Me                         In the event of the DBGrid that you wish to unload the form add this line of code: Timer1.Enabled = True 



Steps to Reproduce
 Start Visual Basic, or if it is already running, select New Project from the File menu.</li> Add a data control to Form1.</li> Set these properties of Data1:

DatabaseName: BIBLIO.MDB

RecordSource: Authors

</li> Add a DBGrid control to the form.</li> Set this single property of DBGrid1:

DataSource: Data1

</li>  Add this line of code to the Click event of the DBGrid control: Private Sub DBGrid1_Click Unload Me  End Sub </li> Press F5 to run the project. Click the DBGrid. You will now get an Unhandled exception in VB32.EXE or a General Protection Fault in module DBGRID16.OCX at 0002:FB7F.</li></ol>

Additional query words: 4.00 vb4win vb4all gp-f gpf gp

Keywords: kbdatabase KB142839

-

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

© Microsoft Corporation. All rights reserved.