ClaraBarton
Registered User.
- Local time
- Today, 08:19
- Joined
- Oct 14, 2019
- Messages
- 584
I've been using this simple sub to delete records (which I very seldom do, so I was unaware...) and discovered I was deleting the wrong record. I believe the problem is in the Me.FilterOn = false line and when I comment it out the proper record is deleted. If I don't turn off the filter, move next creates an empty record that needs to be deleted. Where is the proper place to unfilter this form and show the next record?
Code:
Private Sub cmdDelete_Click()
On Error GoTo Error_Handler
Dim intID As Integer
Dim rs As DAO.Recordset
Dim varResponse As Variant
varResponse = MsgBox("Are you sure you want to delete " & vbLf & _
"this record? " & vbCr, _
vbOKCancel, "Deleting Contacts")
If varResponse = vbOK Then
intID = Me.ContactsID
Me.FilterOn = False
Set rs = Me.RecordsetClone
With rs
.FindFirst "[ContactsID]=" & intID
.Bookmark = Me.Bookmark
.Delete
.MoveNext
End With
rs.Close
Else: Exit Sub
End If
Me.Requery
Exit_Procedure: