RecordsetClone Property [Access 2003 VBA Language Reference]
You can use the RecordsetClone property to refer to a form's Recordset object specified by the form's RecordSource property. Read-only.
expression Required. An expression that returns one of the objects in the Applies To list.
The RecordsetClone property setting is a copy of the underlying query or table specified by the form's RecordSource property. If a form is based on a query, for example, referring to the RecordsetClone property is the equivalent of cloning a Recordset object by using the same query. If you then apply a filter to the form, the Recordset object reflects the filtering.
This property is available only by using Visual Basic and is read-only in all views.
You use the RecordsetClone property to navigate or operate on a form's records 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 methods, that can't be used with forms.
When a new Recordset object is opened, its first record is the current record. If you one of the Find method or one of the Move methods to make any other record in the Recordset object current, you must synchronize the current record in the Recordset object with the form's current record by assigning the value of the DAO Bookmark property to the form's Bookmark property.
You can use the RecordCount property to count the number of records in a Recordset object. The following example shows how you can combine the RecordCount property and the RecordsetClone property to count the records in a form:
Forms!Orders.RecordsetClone.MoveLast MsgBox "My form contains " _ & Forms!Orders.RecordsetClone.RecordCount _ & " records.", vbInformation, "Record Count"
Note If you close the form or if you change the form's RecordSource property, the Recordset object is no longer valid. If you subsequently refer to the Recordset object or to previously saved bookmarks in the form or the Recordset object, an error will occur.
The following example uses the RecordsetClone property to create a new clone of the Recordset object from the Orders form and then prints the names of the fields in the Immediate window.
Sub Print_Field_Names() Dim rst As Recordset, intI As Integer Dim fld As Field Set rst = Me.RecordsetClone For Each fld in rst.Fields ' Print field names. Debug.Print fld.Name Next End Sub
The next example uses the RecordsetClone property and the Recordset object to synchronize a recordset's record with the form's current record. When a company name is selected from a combo box, the FindFirst method is used to locate the record for that company and the Recordset object's DAO Bookmark property is assigned to the form's Bookmark property, causing the form to display the found record.
Sub SupplierID_AfterUpdate() Dim rst As Recordset Dim strSearchName As String Set rst = Me.RecordsetClone strSearchName = Str(Me!SupplierID) rst.FindFirst "SupplierID = " & strSearchName If rst.NoMatch Then MsgBox "Record not found" Else Me.Bookmark = rst.Bookmark End If rst.Close End Sub