topdesk123
Programmer
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
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