Good day folks
I need your help if you may. I have a database with a form bound to a table Patients. I use this form to capture patient information. I have added some code to the beforeUpdate event of the form to prompt the user if the record being entered already exist in the database with the option to view the original record, carry on adding or cancel adding altogether. It works fairly well except for the part where it has to take me to the form to view the original record. It gives me run-time error 3024 (Object Ivalid or no longer set)then highlights the "rsc.FindLast Criteria" part. Code is attached.
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim PID As String
Dim Criteria As String
Dim fAns As Integer
Dim rsc As DAO.Recordset
Set rsc = Me.RecordsetClone
PID = Me.First_Name.Value
Criteria = "[First_Name]=" & "'" & PID & "'"
If DCount("*", "Patients", Criteria) > 0 Then
fAns = MsgBox("This Record Already Exists! Add it Anyway?" _
& vbCrLf & "Click Yes to add, No to jump to existing record, " _
& vbCrLf & "Cancel to go back to editing this record", _
vbYesNoCancel)
Select Case fAns
Case vbYes ' do nothing, let the record be added
Set rsc = Nothing
If MsgBox("You are about to add a record." _
& vbCrLf & vbCrLf & "Do you want to save this record?" _
, vbYesNo, "Record Confirmation") = vbYes Then
DoCmd.Save
Else
DoCmd.RunCommand acCmdUndo
End If
Case vbNo
Cancel = True
Me.Undo
rsc.FindLast Criteria
Me.Bookmark = rsc.Bookmark ' move to last found record
Case vbCancel
Cancel = True ' suppress update, return to form
End Select
End If
End Sub