Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with code to check for duplicates

Status
Not open for further replies.

topdesk123

Programmer
Sep 27, 2001
76
US
Hello everyone,

Can someone help me with the following code - I use it to check for duplicate phone numbers upon data entry - it works great EXCEPT for the Undo function, which I can't figure out how to get to work correctly. After the phone number is entered, if it's a duplicate, a message box pops up notifying the user of the duplication and asking them if they'd like to see the other record. If they say yes - it brings them to it like it should, but leaves the record they had started entering in the table. And no, they don't want to enter the phone number first, I've already asked. I want it to bring them to the other record and remove the record they had started.

Private Sub homephone_AfterUpdate()

On Error GoTo Err_homephone_AfterUpdate
Dim intAnswer As Integer
Dim Txttemp4 As Variant
Txttemp4 = DLookup("[homephone]", "customers", "[homephone] = '" & Forms!customers!HomePhone & "'")
If Not IsNull(Txttemp4) Then
GoTo phoneCheck
phoneCheck:
intAnswer = MsgBox("You already have a customer with this home phone number " & [Txttemp4] & "." & Chr(13) & Chr(10) & "Would you like to review the previous entry?", vbYesNo + vbQuestion, "Possible Duplicate")
Select Case intAnswer
Case vbYes
Dim rs As Object
'Me.Undo
Set rs = Me.Recordset.Clone
rs.FindFirst "[homephone] = '" & Me![HomePhone] & "'"
Me.Bookmark = rs.Bookmark
MsgBox "Thank you. Entry will be cancelled.", vbOKOnly, "Duplicate entry"
Me.Undo
Me.Date.SetFocus
Case vbNo
MsgBox "Thank you. Continue with your entry.", vbOKOnly, "Entry process continuing."
End Select
End If
Exit_homephone_AfterUpdate:
Exit Sub

Err_homephone_AfterUpdate:
MsgBox Err.Description
Resume Exit_homephone_AfterUpdate
End Sub

TIA!
topdesk
 
If the record has already been entered into the table, you should be able to identify it (Primary Key or some other unique data) and then run a delete query.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top