What I Have:
I have an Access input form, the user fills in data in the form, pushes a button which triggers a VBA script which checks if the input telephone number in the [Telephone] control matches an entry in the table. If there's a duplicate it triggers a MsgBox, if not it commits the data to the table. This works and it's great. Here is the script:
Option Compare Database
Private Sub buttonNewRecord_Click()
Dim ErrorInt As Integer
Dim TeleCheck As Variant
TeleCheck = DLookup("[Telephone]", "tblLog", "[Telephone] = '" & Me.Telephone & "'")
If Not IsNull(TeleCheck) Then
MsgBox "Telephone number already exists in the database!"
ErrorInt = ErrorInt + 1
End If
If ErrorInt < 1 Then
DoCmd.GoToRecord , , acNewRec
MsgBox "Record Added!"
End If
End Sub
What I Am Trying To Do:
In the table, along with [Telephone], there is a [Date] and [Customer_Name] field. When a duplicate telephone number is detected, I would like the triggered MsgBox to display the [Date] and [Customer_Name] of the record where the duplicate was found. Like:
MsgBox "Telephone number already exists for [Customer_Name] added on [Date]!"
What I Have Tried:
Not a lot because I'm not sure what to try. Googling provides a lot of different ways to detect a duplicate but I have found no one trying to return any data from the record of the duplicate found.