Microsoft KB Archive/294163

= BUG: ADO Recordset EditMode Property Is Not Set If You Close Form While Editing =

Article ID: 294163

Article Last Modified on 12/3/2003

-

APPLIES TO


 * Microsoft Data Access Components 2.0
 * Microsoft Data Access Components 2.1
 * Microsoft Data Access Components 2.1 Service Pack 2
 * Microsoft Data Access Components 2.1 Service Pack 1
 * Microsoft Data Access Components 2.1 Service Pack 2
 * Microsoft Data Access Components 2.5
 * Microsoft Data Access Components 2.5 Service Pack 1
 * Microsoft Data Access Components 2.6

-



This article was previously published under Q294163



SYMPTOMS
When you edit a TextBox control that is bound to an ActiveX Data Objects (ADO) Recordset object, if you click the Close button or press the ALT+F4 key combination to immediately close the form, the EditMode property returns the adEditNone constant instead of the adEditInProgress constant.



RESOLUTION
To work around this problem, change the focus to another control before you close the form.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce Behavior
 Create a new Standard EXE project in Microsoft Visual Basic 6.0. Form1 is created by default. From the Project menu, click References, and then click Microsoft ActiveX Data Objects 2.x Library . From the Project menu, click Components, and then click Microsoft ADO Data Control 6.0 (OLEDB). Place an ADO Data Control, a CommandButton control, and a TextBox control onto Form1.  Paste the following code in the declarations section of Form1: Option Explicit

Private Sub Form_Load ' Initialize Adodc1. With Adodc1 .ConnectionString = &quot;Provider=SQLOLEDB.1;User ID=myUser;&quot; & _ &quot;Initial Catalog=Pubs;Data Source=MYSERVER;Password=mypassword&quot; .Mode = adModeReadWrite .CursorType = adOpenStatic .LockType = adLockOptimistic .RecordSource = &quot;select * from authors&quot; .CommandType = adCmdText .Refresh End With Set Text1.DataSource = Adodc1 Text1.DataField = &quot;au_fname&quot; End Sub

Sub CheckEditMode Dim intEM As Integer Dim strMsg As String intEM = Adodc1.Recordset.EditMode Select Case intEM Case adEditInProgress strMsg = &quot;adEditInProgress&quot; Case adEditNone strMsg = &quot;adEditNone&quot; Case Else strMsg = &quot;Other&quot; End Select MsgBox &quot;Edit mode: &quot; & CStr(intEM) & &quot; - &quot; & strMsg End Sub

Private Sub Command1_Click Call CheckEditMode End Sub

SendKeys vbTab, True

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) SendKeys vbTab, True 'another workaround:send keystroke to move the cursor Call CheckEditMode End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) Call CheckEditMode End Sub  Modify the code so that the .ConnectionString property assignment in Form_Load points to a valid database.</li> Run the project. Change the field contents in the Textbox control, and press ALT+F4 to close the form. Notice that a message box displays the Edit mode as adEditNone.</li> Run the project again, change the field contents for the TextBox control, and then click Command1. Notice that the expected value for the Edit mode, adEditInProgress, is displayed. Similarly, this value is also displayed if you switch the focus to another control before you close the program.</li></ol>

Additional query words: adodc editmode control box exit adodb datacontrol

Keywords: kbbug kbnofix KB294163

-

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

© Microsoft Corporation. All rights reserved.