ACC2000: Using the AddNew Method with RecordsetClone Moves Form to New Record

ID: Q241025


The information in this article applies to:
  • Microsoft Access 2000

Advanced: Requires expert coding, interoperability, and multiuser skills.

This article applies only to a Microsoft Access database (.mdb).


SYMPTOMS

When you use the AddNew method on a recordset object variable created from the RecordsetClone property of a form, the form incorrectly moves to a new record.


RESOLUTION

Use the Clone method to create a copy of the Recordset property of the form, and then manipulate the copy of the recordset. To use the Clone method with the Recordset property of the form, follow these steps.

CAUTION: Following the steps in this example will modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and perform these steps on a copy of the database.

  1. Open the sample database Northwind.mdb.


  2. Open the Customers form in Design view.


  3. Add a command button to the form with the following properties:


  4. 
       Command button
       ---------------------------
       Name: Command1
       Caption: AddNew
       OnClick: [Event Procedure] 
  5. Set the OnClick property of the command button to the following event procedure:


  6. 
    Private Sub Command1_Click()
       Dim rs As DAO.Recordset
       Set rs = Me.Recordset.Clone
       rs.AddNew
       rs!CustomerID = "AAAAA"
       rs!CompanyName = "AAAAA Company"
       rs.Update
    End Sub 
  7. Save the form and close it.


  8. Open the Customers form in Form view.


  9. Click the command button.


Note that the record is added to the clone of the recordset of the form without affecting the form's current position. To actually see the record, you must requery the form, or close and reopen it.


STATUS

Microsoft has confirmed this to be a problem in Microsoft Access 2000.


MORE INFORMATION

The RecordsetClone property provides a copy, or a clone, of the underlying recordset of the form. The recordset provided by the RecordsetClone property is equivalent to opening a recordset on a table or query, and then using the Clone method to create a copy of that recordset.

Many developers use the RecordsetClone property to move through or to operate on the records of a form, independent of the form itself. For example, you can use the RecordsetClone property when you want to use a method, such as the DAO Find method, that you cannot use with forms.

Microsoft Access 2000 has a new Recordset property that gives developers access to the actual recordset that a form uses. In earlier versions of Access, the RecordsetClone property is available, but it only allows access to a copy of the recordset of a form. By using the new Recordset property, you can use the Clone method to create a copy of the recordset to emulate the behavior of the RecordsetClone property.

Steps to Reproduce Behavior

  1. Follow steps 1 through 3 in the "Resolution" section earlier in this article.


  2. Set the OnClick property of the command button to the following event procedure:


  3. 
    Private Sub Command1_Click()
       Dim rs As DAO.Recordset
       Set rs = Me.RecordsetClone
       rs.AddNew
       rs!CustomerID = "AAAAA"
       rs!CompanyName = "AAAAA Company"
       rs.Update
    End Sub 
  4. Save the form and close it.


  5. Open the Customers form in Form view.


  6. Click the command button.


Note that the form incorrectly moves to a new record and displays the values of the newly added record.

Additional query words: pra

Keywords : kbdta
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbbug


Last Reviewed: January 19, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.