Microsoft Knowledge Base Email Alertz

KBAlertz.com: 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

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **


Bug Tracking Software
For bug tracking software or defect tracking software or issue tracking software, visit Axosoft.


Community Site



We Send hundreds of thousands of emails using ASP.NET Email



Expert Web Design & Graphic Design
Design44.com

ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 289675 - Last Review: March 26, 2007 - Revision: 5.1

You cannot add records or delete records with the ADO AddNew method or with the Delete method

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

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

For a Microsoft Access 2000 version of this article, see 225899  (http://kbalertz.com/Feedback.aspx?kbNumber=225899/EN-US/ ) .

On This Page

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': Object or provider is not capable of performing requested operation.
-or-
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.

CAUSE

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

RESOLUTION

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.

MORE INFORMATION

Steps to Reproduce Behavior

  1. In a new Access database, create the following new table and name it 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 then 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 then 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 that is mentioned in the "Symptoms" section of this article. Also, when you check the table, you see that no records have been deleted.

APPLIES TO
  • Microsoft Office Access 2007
  • Microsoft Office Access 2003
  • Microsoft Access 2002 Standard Edition
Keywords: 
kbprogramming kbperformance kbvba kberrmsg kbprb KB289675
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please