Daniela Z.
New member
- Local time
- Today, 01:47
- Joined
- Dec 13, 2023
- Messages
- 6
Hi there!
Plan: Stuff is written for user review into a temporary table. The table is tied to a form which allows the user to conveniently review the records. Upon button press information contained in the current record gets written to other tables and after successful operation, the current entry in the form is deleted and the next record becomes the current record to review.
Implementation:
Problem: The routine runs well on the first run-through, however, subsequent attempts to run and commit the user reviewed changes on the current record fail with `Error Line: 110, Error: (3420) Object invalid or no longer set.` especially if other records have been deleted from the form's recordset.
I would value some insight on the current problem, especially how to properly delete a form entry from both recordset and recordsetclone without the two getting out of sync. In addition, I would highly appreciate a reference to an authoritative doc that explains the operations on recordsetclones in depth – Andrew Couch's VBA Programming: Inside Out has been a good companion so far, but lacks detailed description of inner workings.
Many thanks in advance to anyone for giving this a read and possible advice!
Plan: Stuff is written for user review into a temporary table. The table is tied to a form which allows the user to conveniently review the records. Upon button press information contained in the current record gets written to other tables and after successful operation, the current entry in the form is deleted and the next record becomes the current record to review.
Implementation:
Code:
Private Sub CommitRecord_Click()
' Hook for rollback via transaction
10 On Error GoTo RollbackAdjustments
' Variable Declartion
Dim strBookmark As String ' recordset bookmark
Dim rsForm As DAO.Recordset
Dim rsSubForm As DAO.Recordset
Dim rsOther As DAO.Recordset
Dim db As DAO.Database
Dim wks As Workspace
20 Set rsForm = Me.RecordsetClone
30 Set rsSubForm = Me!sfrm.Form.RecordsetClone
' Start Transaction
40 Set wks = DBEngine(0)
50 wks.BeginTrans
60 Set db = wks.Databases(0)
' Recordsets init
70 Set rsOther = db.OpenRecordset("tbl", dbOpenTable)
'''
' Commit user changes to tables
''
' Sync record in recordset clone 'rsForm' with current record on form
' (apparently there is no sync between clone and form when using form record selectors)
110 rsForm.Bookmark = Me.Bookmark
' Commit changes here ...
' Transaction sucessful, commit
910 wks.CommitTrans dbForceOSFlush
920 On Error GoTo ErrorHandling
' Deletion of processed entry from form recordset and form recordsetclone
' movenext on the recordsetclone to save the next record's position
930 rsForm.MoveNext
940 If Not rsForm.EOF Then ' if not end-of-file
950 strBookmark = rsForm.Bookmark ' ...save the next record's bookmark
960 rsForm.Bookmark = Me.Bookmark ' ...go back to the record to delete
970 rsForm.Delete ' ...delete the record
980 Me.Requery
990 Me.Bookmark = strBookmark ' ...and return to the saved bookmark
1000 Else
1010 rsForm.Delete ' ...just delete the record
1020 Me.Requery
1030 rsForm.MoveLast ' ...move to the last record
1040 Me.Bookmark = rsForm.Bookmark ' ...position the form to it
1050 End If
1060 Debug.Print "Success!"
ExitProcessing:
' Recordset cleanup
1070 rsForm.Close
1080 Set rsForm = Nothing
1090 rsSubForm.Close
1100 Set rsSubForm = Nothing
1110 rsOtherg.Close
1120 Set rsOther = Nothing
' Transaction & Db cleanup
1190 db.Close
1200 Set db = Nothing
1210 wks.Close
1220 Set wks = Nothing
' Exit
1240 Exit Sub
RollbackAdjustments:
1250 wks.Rollback
ErrorHandling:
1260 Debug.Print "Error Line: " & Erl
1270 Debug.Print "Error: (" & Err.Number & ") " & Err.Description
1280 If Err.Number <> 0 Then
1290 Err.Clear
1300 End If
1310 GoTo ExitProcessing
End Sub
Problem: The routine runs well on the first run-through, however, subsequent attempts to run and commit the user reviewed changes on the current record fail with `Error Line: 110, Error: (3420) Object invalid or no longer set.` especially if other records have been deleted from the form's recordset.
I would value some insight on the current problem, especially how to properly delete a form entry from both recordset and recordsetclone without the two getting out of sync. In addition, I would highly appreciate a reference to an authoritative doc that explains the operations on recordsetclones in depth – Andrew Couch's VBA Programming: Inside Out has been a good companion so far, but lacks detailed description of inner workings.
Many thanks in advance to anyone for giving this a read and possible advice!