Listbox Check Duplicates

padrepio

Registered User.
Local time
Today, 04:41
Joined
Aug 25, 2018
Messages
11
Hi

I've got the following code (following good advice on this forum) but now realise that I need to check for duplicates in the listbox where the NameofEmployee and Department are equal (other columns in the listbox with different values so the records aren't exact matches). I need the Insert Into SQL to be prevented where these fields are equal. The RowSource is a query based on 2 tables. Is there any way of changing the code below to prevent duplicates being selected in the first place? :banghead:


Code:
For Each v2 In Me.ListFrom.ItemsSelected

       sEmployeeName = Me.ListFrom.Column(2, v2)
       sDepartment = Me.ListFrom.Column(3, v2)

dbs.Execute "INSERT INTO EmployeeTbl (nameofemployee,department)VALUES ('" & sEmployeeName & "', '" & sDepartment & "')"

Next v2
 
Don't put them there in the first place.?
Amend the source so that duplicates are not selected.
 
Can you show the query sql for the rowsource of the listbox?
That's where you would remove/prevent duplicates.
 
Rowsource for the ListBox (List From) is below. Employees can belong to more than one department/group hence the way the query is set up. By selecting a department from the DepartmentCmbo (ComboBox on the same form), the List Box is filtered accordingly. By including the department in the list box, it helps the user to validate their selection. Also have a textbox on the form that filters the list (Cmb_ConSearch).

Code:
SELECT EmployeeTbl.EmployeeID, tbEmployeeGroupings.EmployeeGroupID, tbEmployeeGroupings.Nameofemployee_Group, tbEmployeeGroupings.Department AS DepartmentCmbo, EmployeeTbl.StatusOut
FROM EmployeeTbl INNER JOIN tbEmployeeGroupings ON EmployeeTbl.Nameofemployee = tbEmployeeGroupings.Nameofemployee_Group
WHERE (((tbEmployeeGroupings.EmployeeGroupID) Like "*" & [Forms]![SearchEmployeeSignoutForm]![Cmb_ConSearch] & "*") AND ((tbEmployeeGroupings.Department) Like "*" & [Forms]![SearchEmployeeSignoutForm]![Department] & "*") AND ((EmployeeTbl.StatusOut)=No)) OR (((tbEmployeeGroupings.Nameofemployee_Group) Like "*" & [Forms]![SearchEmployeeSignoutForm]![Cmb_ConSearch] & "*") AND ((tbEmployeeGroupings.Department) Like "*" & [Forms]![SearchEmployeeSignoutForm]![Department] & "*") AND ((EmployeeTbl.StatusOut)=No));
 

Users who are viewing this thread

Back
Top Bottom