Reputation: 471
I am using a listbox
to navigate between records on a form but I occasionally get Error Update or CancelUpdate without AddNew or Edit
Run-time Error 3020
on Me.Bookmark = rs.Bookmark
.
I can't seems to figure out what the problem is and was wondering if someone can help me with how to fix it.
Option Compare Database
Option Explicit
Dim rs As DAO.Recordset
Private Sub listBox_AfterUpdate()
Dim rs As DAO.Recordset
If Not IsNull(ItemNo) And Not IsNull(itemName) Then
Set rs = Me.RecordsetClone
rs.FindFirst "[ItemNo] = '" & Me![listBox] & "'"
If Not rs.NoMatch Then Me.Bookmark = rs.Bookmark
Else
Exit Sub
End If
If IsNull(ItemNo) Or IsNull(itemName) Then
Exit Sub
End If
rs.Close
Set rs = Nothing
End Sub
Upvotes: 0
Views: 899
Reputation: 381
I came across this issue. For me at least, I noticed it would happen under the following conditions:
listbox
which is the same record as the current record,I was able to prevent the error either by saving the record before setting Me.Bookmark = rs.Bookmark
(as suggested by Olivier Jacot-Descombes) or by comparing the values of Me.Bookmark and rs.Bookmark to make sure they were not the same.
If StrComp(rs.Bookmark, Me.Bookmark, 0) <> 0 Then
If Not rs.NoMatch Then Me.Bookmark = rs.Bookmark
End If
Upvotes: 1
Reputation: 112402
You have probably started to edit the record in the Form. Save the pending edits before moving to another record.
If Not rs.NoMatch Then
Me.Dirty = False 'Saves any pending changes.
Me.Bookmark = rs.Bookmark 'Navigate to another record.
End If
Upvotes: 1