hello and good day to you all!
I have an issue with my VBA coding and I must inform you that my VBA is not up to par. I have little understanding of it. I think this example, however, is straight forward. I have form, Contacts Form, that is used to update all my contacts in my table, tblContacts. My VBA coding is suppose to (when I save or close the form) tell me that the First name AND Last name that I entered already exists. Then it is suppose to ask me if I would like to go to that record source.
As you can probably tell, I am trying to reduce duplicate values to a certain degree. Granted there could be 2 DIFFERENT bob smiths and I wouldn't want to eliminate the possibility of not including both. Below is my current code. The code works fine for all the red portion (it prompts me before closing or saving and the correct dialogue box comes up). But as soon as I try to execute the green portion (by selecting "yes"), I get the error: "Run-time error '3021': No current record."
I believe what I really need is a command that will take me to the record that has the same first and last name (there could even be a possibility of more than 1 similar contact I'd assume).
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.NewRecord Then
ContactNumber = Nz(DFirst("ID", "tblContacts", "[First Name]='" & txtFirstName & "' AND [Last name]='" & txtLastName & "'"))
If ContactNumber <> 0 Then
Response = MsgBox("This name already exists." & vbCrLf & "Do you want to go to that record?", vbYesNo)
If Response = vbYes Then
DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
Set rs = Me.Recordset.Clone
rs.FindFirst "[CustID] = " & ContactNumber
Me.Bookmark = rs.Bookmark
End If
End If
End If
End Sub
Thank you in advance for you time in reading this and helping