Can't add or delete records with ADO methods – Microsoft 365 Apps

Microsoft Technical Article






Technical Guide: Resolving ADO Recordset Update Errors in Microsoft Access

🚀 Overview

In Microsoft Access environments—including standard database formats (.mdb, .accdb) and Access Projects (.adp)—IT administrators and developers often utilize ActiveX Data Objects (ADO) to programmatically manage data. A common hurdle encountered during this process is the inability to append or remove records using the AddNew or Delete methods.

When these operations are attempted on a Recordset that has been initialized with default settings or an unspecified lock type, the application will trigger a Run-time error ‘3251’. This error indicates that the underlying provider or the current configuration does not support the requested data manipulation. This guide provides the technical breakdown of why this occurs and the specific code adjustments required to permit data modifications.

⚙️ Key Technical Details

  • Default Locking Behavior: By design, ADO Recordsets default to adLockReadOnly if a specific lock type is not declared during the Open method. In this state, the Recordset is strictly “read-only,” and any attempt to modify the data buffer results in a provider error.
  • Required References: For ADO code to execute successfully within the Visual Basic for Applications (VBA) environment, the project must have a reference to the Microsoft ActiveX Data Objects 2.x Library (version 2.1 or later).
  • Error Variants: Admins may encounter different strings for Error ‘3251’ depending on the specific provider, such as:

    • “Object or provider is not capable of performing requested operation.”
    • “The operation requested by the application is not supported by the provider.”
    • “Current Recordset does not support updating. This may be a limitation of the provider, or of the selected locktype.”
  • Corrective Lock Types: To enable write access, the Recordset must be opened using one of the following:

    • adLockOptimistic: Locks records only when the Update method is called.
    • adLockPessimistic: Locks records immediately upon editing to ensure data integrity in high-concurrency environments.

đź’» Resolution & Code Implementation

To resolve the error, explicitly define the lock type parameter in your Recordset connection logic. Below is the corrected implementation:

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

⚠️ Impact

For IT Administrators managing legacy or custom Access-based ERP/reporting tools, this issue can cause critical failures in automated data-processing tasks. If internal tools are migrated or updated, ensuring that the adLockOptimistic or adLockPessimistic flags are explicitly set is vital for maintaining business continuity. Furthermore, ensuring that the correct ADO library references are deployed across the workstation fleet is a prerequisite for these scripts to function.

đź§Ş Steps to Reproduce the Error

If you need to validate this behavior in a test environment, follow these steps:

  1. Create a table named TestTable with an AutoNumber field ID (Primary Key) and a Text field Name.
  2. Populate the table with sample data.
  3. In the VBA Editor, ensure Option Explicit is declared.
  4. Execute the following faulty code in the Immediate window:
Sub DelFirstRec()
   Dim rs As New ADODB.Recordset

   rs.Open "Select * from TestTable", CurrentProject.Connection, adOpenKeyset
   rs.MoveFirst
   rs.Delete
   rs.Close
End Sub

Because the code above omits the lock type, the provider defaults to read-only, and the rs.Delete command will fail with Error ‘3251’.


Official Source: Read the full article on Microsoft.com