Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

ACC2000: Can't Add or Delete Records with ADO AddNew or Delete Method


View products that this article applies to.

This article was previously published under Q225899
Advanced: Requires expert coding, interoperability, and multiuser skills.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).

For a Microsoft Access 2002 version of this article, see 289675 (http://support.microsoft.com/kb/289675/EN-US/ ) .

↑ Back to the top


Symptoms

When you are using ActiveX Data Objects (ADO), if you use the AddNew or Delete method of the Recordset object, and you open the recordset with an unspecified lock type, you may receive one of the following error messages:
Run-time error '3251':
The operation requested by the application is not supported by the provider.
or
Run-time error '3251':
Current Recordset does not support updating. This may be a limitation of the provider, or of the selected locktype.

↑ Back to the top


Cause

By default, ADO recordsets are opened with a lock type of adLockReadOnly, which does not allow additions and deletions.

↑ Back to the top


Resolution

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. To allow additions and deletions, open the recordset with a lock type of either adLockOptimistic or adLockPessimistic, as in the following code sample:
Sub DelFirstRec()
   Dim rs As ADODB.Recordset
   Set rs = New ADODB.Recordset

   rs.Open "Select * from TestTable", CurrentProject.Connection, _
            adOpenKeyset, adLockOptimistic
   rs.MoveFirst
   rs.Delete
   rs.Close
End Sub
				
NOTE: You can use this sample code to resolve the behavior in the "Steps to Reproduce Behavior" section of this article.

↑ Back to the top


More information

Steps to Reproduce Behavior

  1. In a new Access database, create the following new table called TestTable:
       Table: TestTable
       ----------------------------
       Field Name: ID
       Data Type: Autonumber
       Indexed: Yes (No Duplicates)
    
       Field Name: Name
       Data Type: Text
    					
  2. Open the new table in Datasheet view and type the following test data:
       ID    Name
       -----------------
       1    Beverages
       2    Condiments
       3    Confections
       4    Dairy
       5    Grains
       6    Meat
       7    Produce
       8    Seafood
    					
  3. NOTE: The sample code in this article uses Microsoft ActiveX Data Objects. For this code to run properly, you must reference the Microsoft ActiveX Data Objects 2.x Library (where 2.x is 2.1 or later.) To do so, click References on the Tools menu in the Visual Basic Editor, and make sure that the Microsoft ActiveX Data Objects 2.x Library check box is selected.

    Create a module and type the following line in the Declarations section if it is not already there:
    Option Explicit
    					
  4. Type the following procedure:
     
    Sub DelFirstRec()
       Dim rs As New ADODB.Recordset
    
       rs.Open "Select * from TestTable", CurrentProject.Connection, adOpenKeyset
       rs.MoveFirst
       rs.Delete
       rs.Close
    End Sub
    					
  5. To test this function, type the following line in the Immediate window, and then press ENTER:
    DelFirstRec
    Note that you receive the error message described in the "Symptoms" section of this article. Also, when you check the table, you see that no records have been deleted.

↑ Back to the top


References

For more information about ADO recordsets, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type ado recordset in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

↑ Back to the top


Keywords: KB225899, kbprb

↑ Back to the top

Article Info
Article ID : 225899
Revision : 3
Created on : 6/23/2005
Published on : 6/23/2005
Exists online : False
Views : 305