Using Bookmark and RecordsetClone
Hello,
I'm trying to use the Bookmark and RecordsetClone code from pages 194-195.
I am receiving an error Me.PCKey Method or data Member not found
What am I doing incorrectly? I have tried this in the After Update event and the On Click event of a Save Command Button
Thanks,
Here is my Code
On Error GoTo Error_Handler
Dim db As Database
Dim rstPC As DAO.rstordset
Dim rstSpecFrom As DAO.rstordset
Dim rstSpecTo As DAO.Recordset
Dim lngPCKey As Long
Set db = CurrentDb
If Not IsNull(Me.PCKey) Then
Set rstPC = db.OpenRecordset("tblPC", dbOpenDynaset)
' copy the parent record and remember its key
rstPC.AddNew
rstPC!PCName = "Copy of " & Me!PCName
rstPC.Update
rstPC.Bookmark = rstPC.LastModified
lngPCKey = rstPC!PCKey
rstPC.Close
Set rstPC = Nothing
Set rstSpecTo = db.Openrstordset("tblSpecification", dbOpenDynaset)
Set rstSpecFrom = db.OpenRecordset _
("Select * From tblSpecification Where PCKey = " & Me!PCKey)
Do While Not rstSpecFrom.EOF
rstSpecTo.AddNew
rstSpecTo!PCKey = lngPCKey 'set to the new parent key
rstSpecTo!SpecificationName = rstSpecFrom!SpecificationName
rstSpecTo!SpecificationQty = rstSpecFrom!SpecificationQty
rstSpecTo.Update
rstSpecFrom.MoveNext
Loop
rstSpecTo.Close
Set rstSpecTo = Nothing
rstSpecFrom.Close
Set rstSpecFrom = Nothing
Me.Requery
'reposition form to new record
Set rstPC = Me.RecordsetClone
rstPC.FindFirst "PCKey = " & lngPCKey
If Not rstPC.EOF Then
Me.Bookmark = rstPC.Bookmark
End If
rstPC.Close
Set rstPC = Nothing
End If
Exit_Procedure:
On Error Resume Next
Set db = Nothing
Exit Sub
Error_Handler:
DisplayUnexpectedError Err.Number, Err.Description
Resume Exit_Procedure
Resume
Last edited by poolmd; April 6th, 2013 at 01:50 PM..
Reason: Added code
|