nuct
Programmer
- Sep 5, 2001
- 103
Hi im trying to set up our HR database so that it prevents users from entering duplicate records. Im reasonably sure that I must use the beforeupdate event the dlookup function in some way to do this. However my code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
' used to find duplicates
Dim SurName, ForeName As String
Me.txtSurname.SetFocus
SurName = Me.txtSurname.Text
Me.txtForename.SetFocus
ForeName = Me.txtForename.Text
If Nz(DLookup("[forename]", "dbo_tblStaff", "[surname] = '" & SurName & "' AND [forename] = '" & ForeName & "' "), 0) <> 0 Then
Cancel = True
End If
End Sub
does not seem to work. The application just freezes on the current record if it is a duplicate.
Has anybody got any ideas?
Simon
Private Sub Form_BeforeUpdate(Cancel As Integer)
' used to find duplicates
Dim SurName, ForeName As String
Me.txtSurname.SetFocus
SurName = Me.txtSurname.Text
Me.txtForename.SetFocus
ForeName = Me.txtForename.Text
If Nz(DLookup("[forename]", "dbo_tblStaff", "[surname] = '" & SurName & "' AND [forename] = '" & ForeName & "' "), 0) <> 0 Then
Cancel = True
End If
End Sub
does not seem to work. The application just freezes on the current record if it is a duplicate.
Has anybody got any ideas?
Simon