Run-Time error 2001

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello from Belgium,

In Office Access 2003, I am building an application in which there is a
table (tblEmployees) to enter the identification of the employees working in
a company.
I am trying to avoid duplicate records by searching the existence or the
absence of a duplicate Last Name in the [Last Name] field. I created a VBA
code to capture and verify the Last Name but I am facing a problem that I do
not find how to solve it as I have verified every single word of my code.
Here follows the code:

Private Sub LastName_AfterUpdate() 'LastName being the name of the control
for inputting the Last Name
Dim Check As Integer
Dim MsgString As String
Check = DCount("[Last Name]", "tblEmployees", "[Last Name]='" &
Me![LastName] & "'")
If Check <> 0 Then
MsgString = ""
MsgString = MsgString & "That " & FieldToCheck & " "
MsgString = MsgString & "has already been used!" & Chr(13)
MsgString = MsgString & "Duplicates are unauthorized!"
Me.Undo
Me.Undo
End If
End Sub

Every time, I am trying to run the application, when the
LastName_AfterUpdate event is called, I keep receiving a Run-time Error
'2001' stating "You canceled the previous operation". Of course, there is
nothing in the help file to explain me what is going on.

Could you please help me?

Thanks beforehand,

Mr. Guilbeau
 
What happens if two people with the same surname work in your company?

You could set the surname as a primary key but that will restrict you to
only one surname.

Do the employees have a employee id, staff id, photo id card etc.? You could
use these a reference number for each employee then you would not have to
worry about duplicate entries.
 
Back
Top