Link to home
Start Free TrialLog in
Avatar of Derek Brown
Derek BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Duplicates Check

What is the best way to check for duplicates in a form based on a select query

I have a continuous form where users enter information (a list of numbers). When the list is so long that it goes off the page it would be nice if rather than check to see if they already have the next entry in the list that the program gives message "You already have that number listed." I cannot use the tables no duplicates as the table holds data for a number of lists and will need to store duplicates.
Avatar of mbizup
mbizup
Flag of Kazakhstan image

You could use a check like this in the After Update event of the textbox where the user is entering data:

Dim rs as dao.recordset
set rs = me.recordsetclone

rs.FindFirst "YourField = " & me.txtNumber
if rs.Nomatch = False then msgbox "This is a duplicate"

rs.close
set rs = Nothing

Open in new window


The above assumes the field we are checking is numeric.  If it is text, rewrite line 4 like this:

rs.FindFirst "YourField = '" & me.txtNumber & "'"

Open in new window

SOLUTION
Avatar of Ryan
Ryan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Derek Brown

ASKER

Thank you both