T
Tony Williams
I have a form which is used to collect data on individuals. So I have two
controls txtfirstname and txtsurname. Before the record is saved I want code
to check whether the combination of txtfirstname and txtsurname already
exists in another record. If it does I want a form to open,
frmduplicatenames, which shows all the duplicates. I have attempted to
create a pretty basic VBA code that illustrates what I want to do but as I'm
not a VBA expert it doesn't work but I think it shows where I want to be.
Here is my attempt at the code which I have put in the BeforeUpdate event of
the control txtsurname:
Private Sub txtsurname_BeforeUpdate(Cancel As Integer)
Dim strname As String
Dim strform As String
strname = "[txtfirstname] & [txtsurname]"
strform = "frmduplicatenames"
If strname = Me.txtfirstname & Me.txtsurname Then
DoCmd.OpenForm strform, acNormal, , Me.txtsurname =
[tbl.individuals].[txtsurname]
End If
End Sub
Can anyone help me with this please?
controls txtfirstname and txtsurname. Before the record is saved I want code
to check whether the combination of txtfirstname and txtsurname already
exists in another record. If it does I want a form to open,
frmduplicatenames, which shows all the duplicates. I have attempted to
create a pretty basic VBA code that illustrates what I want to do but as I'm
not a VBA expert it doesn't work but I think it shows where I want to be.
Here is my attempt at the code which I have put in the BeforeUpdate event of
the control txtsurname:
Private Sub txtsurname_BeforeUpdate(Cancel As Integer)
Dim strname As String
Dim strform As String
strname = "[txtfirstname] & [txtsurname]"
strform = "frmduplicatenames"
If strname = Me.txtfirstname & Me.txtsurname Then
DoCmd.OpenForm strform, acNormal, , Me.txtsurname =
[tbl.individuals].[txtsurname]
End If
End Sub
Can anyone help me with this please?