Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I create a clone of a record set that is NOT in synch with the original?

Status
Not open for further replies.

weightinwildcat

Programmer
May 11, 2010
84
US
I need to clone or otherwise duplicate a record set of a sub-form. I need to be able to look at original values to see if any changes have been made.
 
The form object has a built in recordset and recordsetclone properties.
 
That I know. The problem is that the recordset and the recordset clone tend to be pretty closely synchronized. I need a programmatic way of knowing if any field of a record has been changed in any way, and by how much.
 
Not tested, just an idea here...

Code:
Dim intF As Integer

recOrgin.MoveFirst
recClone.MoveFirst

Do While Not recOrgin.EOF
    For intF = 1 To recOrgin.Fields.Count
        If recOrgin.Fields(intF).Value <> recClone.Fields(intF).Value Then[green]
            'Do your magic here[/green]
        End If
    Next intF
    recOrgin.MoveNext
    recClone.MoveNext
Loop

Have fun.

---- Andy

There is a great need for a sarcasm font.
 
You are thinking along the correct lines, but if I change an entry in the recordset it will be picked up by the recordset clone, on account of them being synchronized. What I need is to have a copy of the recordset that is NOT synchronized, so that the original data will still be available for comparison.
 
As I pointed out in an earlier thread you need to institute logging. You are not going to get there from here with any native functionality. It is not that hard, and the example I provided contained the code. A clone will not work as pointed out. The recordsetclone is what is known as a shallow clone. A new object is created, but it contains pointers to all the "child objects". So it does not create a new fields collection of field objects but only holds a pointer to those fields. So both recordsets are pointing to the same fields no a copy of the fields.

You could write code to deep clone a recordset but it would have to be done using ADO disconnected recordsets. This would be extremely cumbersome and complicated I would think. Just institute basic logging and be done.
 
It isn't that hard to do proper Clone. See my example code in thread222-1115911
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top