Microsoft KB Archive/257787

= FIX: Program with UserControl Causes Access Violation When Exiting =

Article ID: 257787

Article Last Modified on 8/7/2007

-

APPLIES TO


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

-



This article was previously published under Q257787



SYMPTOMS
When an ActiveX control with two UserControl objects is created, one UserControl acts as a data source and the other acts as a data consumer (bound to a data source.) When another ActiveX control is created that includes the two preceding UserControls and binds them together, a client program that uses the last UserControl in the compiled program crashes with an Access Violation in Msvbvm60.dll when it exits.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This bug was corrected in the latest service pack for Visual Studio 6.0.

For additional information about Visual Studio service packs, click the following article numbers to view the articles in the Microsoft Knowledge Base:

194022 INFO: Visual Studio 6.0 Service Packs, What, Where, Why

194295 HOWTO: Tell That a Visual Studio Service Pack Is Installed

To download the latest Visual Studio service pack, visit the following Microsoft Web site:

http://msdn2.microsoft.com/en-us/vstudio/Aa718353.aspx



Steps to Reproduce Behavior
 Start a Visual Basic ActiveX Control project. UserControl1 is created by default. On the Project menu, choose References to open the References dialog box, check Microsoft ActiveX Data Objects 2.1 Library, and click OK. Set the DataBindingBehavior property of UserControl1 to 1 - vbSimpleBound. Add a TextBox control on UserControl1. Text1 is created by default.  Add the following code to the General Declarations section of UserControl1: Option Explicit

Public Property Get Text As Variant Text = Text1.Text End Property

Public Property Let Text(ByVal New_Text As Variant) Text1.Text = New_Text PropertyChanged "Text" End Property

' Load property values from storage Private Sub UserControl_ReadProperties(PropBag As PropertyBag) Text1.Text = PropBag.ReadProperty("Text", Text1) End Sub

' Write property values to storage Private Sub UserControl_WriteProperties(PropBag As PropertyBag)

Call PropBag.WriteProperty("Text", Text1.Text, Text1) End Sub  On the Tools menu, choose Procedure Attributes.</li> Set the contents of the Name combo box to Text.</li> Click the Advanced button, choose the following items, and click OK: <ul> Property is data bound</li> This property binds to DataField</li> Show DataBindings collection at design time</li> Property will call CanPropertyChange before changing</li> Update immediate</li></ul> </li> On the Project menu, select Add User Control. UserControl2 is created by default.</li> Set the DataSourceBehavior Property of UserControl2 to 1 - vbDataSource.</li> Add a Shape control on UserControl2.</li>  Add the following code to the General Declarations section of UserControl2.NOTE: You need to change the path to Biblio.mdb in the UserControl_Initialize event procedure if Visual Basic 6.0 is not installed on your C Drive. Option Explicit Dim TheConn As New ADODB.Connection Dim rs As ADODB.Recordset

Private Sub UserControl_GetDataMember(DataMember As String, Data As Object) Set Data = rs End Sub

Public Property Get Recordset As Variant Recordset = rs End Property

Private Sub UserControl_Initialize Dim tmp As String tmp$ = "Provider=Microsoft.Jet.OLEDB.4.0;" tmp$ = tmp$ & "Data Source=C:\Program Files\Microsoft Visual " _ & "Studio\VB98\BIBLIO.MDB;Persist Security Info=False"

TheConn.ConnectionString = tmp$ TheConn.Open Set rs = TheConn.Execute("select * from authors") End Sub

Private Sub UserControl_Terminate 'On Error Resume Next On Error GoTo errHandler rs.Close TheConn.Close Exit Sub

errHandler: MsgBox "Error in UserControl_Terminate" & Err.Number & " " & Err.Description End Sub

Public Sub MoveNext If Not rs.EOF Then rs.MoveNext End If End Sub

Public Sub MovePrevious If Not rs.BOF Then rs.MovePrevious End If End Sub

Public Sub MoveFirst rs.MoveFirst End Sub

Public Sub MoveLast rs.MoveLast End Sub

</li> On the File menu, choose Make Project1.ocx to compile the project.</li> On the File menu, choose Add Project to create an ActiveX control project. Project2 is added by default.</li> Change the Name property of UserControl1 in Project2 to UserControl3.</li> Add a UserControl1 on UserControl3. UserControl11 is added by default.</li> Place a UserControl2 on UserControl3. UserControl21 is added by default.</li> <li>Set the following properties of UserControl11: <ul> <li>Set the DataSource property to UserControl21.</li> <li>Set DataField property to Au_ID.</li></ul> </li> <li>On the File menu, choose Make Project2.ocx to compile Project2.</li> <li>On the File menu, choose Add Project to add a Standard EXE project. Project3 is added by default.</li> <li>Add UserControl3 on Form1 of Project3.</li> <li>On the File menu, choose Make Project3.exe to compile the project.</li> <li>Start Microsoft Windows Explorer, double-click Project3.exe, and note that Form1 is displayed.</li> <li>Close Form1, and note that an Access Violation occurs.</li></ol>

Additional query words: sp4

Keywords: kbbug kbctrl kbfix kbvs600sp4fix kbvs600sp5fix KB257787

-

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

© Microsoft Corporation. All rights reserved.