Me.Form.Bookmark = rst.Bookmark runs OK most of the times. but causing runtime error 3420 from time to time. It's myterious to me. Can anyone help me?
Private Sub Customer_AfterUpdate()
Dim strCustomer As String
Dim dbBible As DAO.Database
Dim rst As DAO.Recordset
Dim strCriteria As String
Dim CustomerID As Integer
If Not IsNothing(Me.Customer) Then
strCustomer = Me.Customer
CustomerID = DLookup("Customer_ID", "tblCustomers", "Customer = '" & strCustomer & "'")
strCriteria = "Customer_ID=" & CustomerID
Set dbBible = CurrentDb
Set rst = dbBible.OpenRecordset("tblCustomers", dbOpenDynaset)
If rst.NoMatch Then
MsgBox "No entry found.", vbInformation
Me.Customer = rst!Customer
On Error Resume Next
Me.Form.Bookmark = rst.Bookmark
If TempVars!frmWorkOrdersOpen = 1 Then
Forms!frmWorkOrders.Company = rst!Customer
Forms!frmWorkOrders.Contact = rst!Contact
Forms!frmWorkOrders.Street = rst!Street
Forms!frmWorkOrders.City = rst!City
Forms!frmWorkOrders.State = rst!State
Forms!frmWorkOrders.Zip_Code = rst!Zip_Code
Forms!frmWorkOrders.Phone = rst!Phone
Set rst = Nothing
Set dbBible = Nothing
have you tried setting a breakpoint and running it until you get the error? I'd personally implement a different error handling logic to catch the error. If, instead of On Error Goto Next, you put in On Error Goto errorhandler, and then put in an errorhandler section at the bottom, where it would pop up a msgbox if err.Number = 3420, you could Ctrl-Break when you got the msgbox. Then you could see what your values were and find the problem. That make any sense, or have you already tried that?
Set rst = Me.RecordsetClone worked. I appreciate your help.
Still I don't understand the difference between RecordsetClone and OpenRecordSet.
Thank you so much.
Sorry for late reply but have been on hol.
From seven or eight years ago when first looking at bookmrks etc, I seem to remember that bookmark are randomly generated for each record when the recordset is CREATED AND/OR REQUERIED. Therefore even with a given recordset (or form records) bookmark(s) for a given record change when you requery them, and bookmarks will be different for a given record between two recordset created from the same SQL stament.
The RecordsetClone (by refinituion!) is identical to ther Form Recordset, therefore the bookmarks are the same (until you requiry the form).
For this reason I tend to use the PK(s) to identify records