Clone Method Example

The example creates a duplicate Dynaset from the recordset of a data control, and then in the Validate event, searches for a duplicate record in the cloned Dynaset in order to validate the entry when a user is attempting to add a new record.

' Declarations section.
Dim MyDup As Dynaset

Sub Form_Load ()
  Data1.DatabaseName = "BIBLIO.MDB"      ' Set data properties.
  Data1.RecordSource = "Authors"
  Data1.Refresh                          ' Open database.
  Set MyDup = Data1.Recordset.Clone()    ' Clone recordset.
Sub Data1_Validate ()
  ' Make sure a change has taken place.
  If Not Text1.DataChanged Then Exit Sub
  ' In the cloned recordset, find a matching record.
  MyDup.Find "Author = " & Text1.Text
  If Not MyDup.NoMatch Then              ' If a match is found...