I'm having some issues with stopping duplicate entries in a table and have tried a copule different ways with no avail.
In one table in particular, I have a table holding employees as followed;
EmployeeID: PK
FirstName
MInitial
LastName
Company:FK
DepartmentFK
What I am trying to do is stop the ability to duplicating records over a series of fields (FirstName, MInitial, LastName, Company)rather than just one specific field.
I attempted to index the table as followed;
EmployeeID: PK/Unique
FirstName: Unique
MInitial: Unique
LastName: Unique
Company: Unique
The problem with this is it wont allow me to enter more than one person with the same first, middle, or last name or company.
I tried "DCount" Code in a form with no luck, that code reads as followed:
Note: this code was initially used on a different database I was working on that accounted for an individuals First Name, Last Name, and Date of Birth which worked great. I am just trying to apply that similar concept to this new database with first name, middleinitial, last name, and company; which will be a foreign key.
Not all too familiar with vba, im running out of thoughts. Can anyone plese help me with this or suggest an alternative method?
Thank you in advance for help. It's greatly appreciated.
:banghead:
In one table in particular, I have a table holding employees as followed;
EmployeeID: PK
FirstName
MInitial
LastName
Company:FK
DepartmentFK
What I am trying to do is stop the ability to duplicating records over a series of fields (FirstName, MInitial, LastName, Company)rather than just one specific field.
I attempted to index the table as followed;
EmployeeID: PK/Unique
FirstName: Unique
MInitial: Unique
LastName: Unique
Company: Unique
The problem with this is it wont allow me to enter more than one person with the same first, middle, or last name or company.
I tried "DCount" Code in a form with no luck, that code reads as followed:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If DCount("*", "tblEmployees", "[firstname]=" & Chr(34) & Me!firstname & Chr(34) & _
" And [MInitial]=" & Chr(34) & Me!MInitial & Chr(34) & _
" And [LastName]=" & Chr(34) & Me!LastName & "#") > 0 Then
Msgbox "Person already exists."
Cancel = True
End If
End Sub
Note: this code was initially used on a different database I was working on that accounted for an individuals First Name, Last Name, and Date of Birth which worked great. I am just trying to apply that similar concept to this new database with first name, middleinitial, last name, and company; which will be a foreign key.
Not all too familiar with vba, im running out of thoughts. Can anyone plese help me with this or suggest an alternative method?
Thank you in advance for help. It's greatly appreciated.
:banghead: