BUG: ADO Recordset EditMode Property Is Not Set If You Close Form While Editing (294163)



The information in this article applies to:

  • Microsoft Data Access Components 2.0
  • Microsoft Data Access Components 2.1
  • Microsoft Data Access Components 2.1 (GA)
  • Microsoft Data Access Components 2.1 SP1
  • Microsoft Data Access Components 2.1 SP2
  • Microsoft Data Access Components 2.5
  • Microsoft Data Access Components 2.5 SP1
  • 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.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Create a new Standard EXE project in Microsoft Visual Basic 6.0. Form1 is created by default.
  2. From the Project menu, click References, and then click Microsoft ActiveX Data Objects 2.x Library .
  3. From the Project menu, click Components, and then click Microsoft ADO Data Control 6.0 (OLEDB).
  4. Place an ADO Data Control, a CommandButton control, and a TextBox control onto Form1.
  5. Paste the following code in the declarations section of Form1:
    Option Explicit
    
    Private Sub Form_Load()
       ' Initialize Adodc1.
       With Adodc1
        .ConnectionString = "Provider=SQLOLEDB.1;User ID=myUser;" & _
            "Initial Catalog=Pubs;Data Source=MYSERVER;Password=mypassword"
        .Mode = adModeReadWrite
        .CursorType = adOpenStatic
        .LockType = adLockOptimistic
        .RecordSource = "select * from authors"
        .CommandType = adCmdText
        .Refresh
       End With
       Set Text1.DataSource = Adodc1
       Text1.DataField = "au_fname"
    End Sub
    
    Sub CheckEditMode()
        Dim intEM As Integer
        Dim strMsg As String
        intEM = Adodc1.Recordset.EditMode
        Select Case intEM
            Case adEditInProgress
                strMsg = "adEditInProgress"
            Case adEditNone
                strMsg = "adEditNone"
            Case Else
                strMsg = "Other"
        End Select
        MsgBox "Edit mode: " & CStr(intEM) & " - " & 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
    					
  6. Modify the code so that the .ConnectionString property assignment in Form_Load() points to a valid database.
  7. 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.
  8. 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.

Modification Type:MajorLast Reviewed:12/3/2003
Keywords:kbbug kbnofix KB294163