Microsoft KB Archive/304267

= FIX: Error in VBA6.DLL Using a Late Bound Recordset When at BOF or EOF =

Article ID: 304267

Article Last Modified on 5/8/2003

-

APPLIES TO

 Microsoft Visual Basic 6.0 Enterprise Edition, when used with:  Microsoft Data Access Components 2.6

 Microsoft Data Access Components 2.6 Service Pack 1

 Microsoft Data Access Components 2.7  Microsoft Visual Basic 6.0 Professional Edition, when used with:  Microsoft Data Access Components 2.6</li></ul>

 Microsoft Data Access Components 2.6 Service Pack 1</li></ul>

 Microsoft Data Access Components 2.7</li></ul> </li> Microsoft Visual Basic 6.0 Learning Edition, when used with:  Microsoft Data Access Components 2.6</li></ul>

 Microsoft Data Access Components 2.6 Service Pack 1</li></ul>

 Microsoft Data Access Components 2.7</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q304267

<div class="symptoms_section">

SYMPTOMS
If you reference a field value in an ActiveX Data Objects (ADO) recordset when BOF or EOF is true, if you use late binding, and if you concatenate it to a string, an unhandled exception occurs in VBA6.DLL and causes an error.

Under Windows 95 or Windows 98, you receive the following error message:

VB6 Has Caused An Error in VBA6.DLL

Under Windows NT 4.0, you receive the following Dr. Watson error:

An application error has occurred and an application error log is being generated. VB6.EXE. Exception: access violation (0xc0000005) address 0x0fa91abd

Under Windows 2000, Visual Basic quits.

<div class="cause_section">

CAUSE
If you pass a reference to an ADO field value when BOF or EOF is true, the following error message normally appears:

Either BOF or EOF is true, or the current record has been deleted. Requested operation requires a current record.

However, if you reference a field value in an ADO recordset when BOF or EOF is true, if you use late binding, and if you concatenate it to a string, an unhandled exception occurs in VBA6.DLL and causes the above-mentioned error messages.

<div class="status_section">

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 Visual Basic 6.0 Service Pack 3.

<div class="moreinformation_section">

Steps to Reproduce Behavior
<ol> Open a new Standard EXE project in Visual Basic. Form1 is created by default.</li> Place a command button on Form1.</li>  Add the following code to the button's click event: Dim strConn As String Dim strSQL As String strConn = &quot;provider=sqloledb;data source=stevenbr01;initial catalog=northwind;user id=sa;&quot; strSQL = &quot;SELECT * FROM Customers&quot; Set cn = CreateObject(&quot;ADODB.Connection&quot;) Set rs = CreateObject(&quot;ADODB.Recordset&quot;) cn.Open strConn rs.CursorLocation = 3 rs.Open strSQL, cn, 1, 1 While Not rs.EOF For i = 0 To rs.fields.Count - 1 If Not IsNull(rs.fields(i).Value) Then Debug.Print rs.fields(i).Value & &quot;&quot; End If   Next rs.movenext Wend Debug.Print &quot;value &quot; & rs.fields(&quot;contactname&quot;) '<this fails 'Debug.Print rs.fields(&quot;contactname&quot;) '<this works </li> <li>Modify the ADO connection string in the strConn variable as appropriate for your environment.</li> <li>Run the project, and click the command button. Notice that data scrolls by in the Immediate window. When the recordset is fully read, you receive the above-mentioned error messages.</li> <li>To see the error that should occur under these circumstances, comment the first Debug.Print line and uncomment the second one, which does not concatenate the field value to the word &quot;value &quot; in the print statement. Then, rerun the project.</li></ol>

Additional query words: VBA6.dll

Keywords: kbbug kbfix kbvbp600fix KB304267

-

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

© Microsoft Corporation. All rights reserved.