473,405 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Checking For Duplicate IDs

gregoryt2002
I have just created a database and need to set up a rule so that when someone enters a certain ID into the form it checks it against the ID's already in the database and returns a error message if it already exists.

Im afraid im a bit of a novice so if anyone can help it would be very appreciated.

Thanks
Apr 4 '07 #1
14 2009
MMcCarthy
14,534 Expert Mod 8TB
I have just created a database and need to set up a rule so that when someone enters a certain ID into the form it checks it against the ID's already in the database and returns a error message if it already exists.

Im afraid im a bit of a novice so if anyone can help it would be very appreciated.

Thanks
Just open the table in design view. Go to the ID field and set Indexed property to Yes (No Duplicates). This will prevent the same ID being entered twice.

Mary
Apr 4 '07 #2
The Indexed property to Yes (No Duplicates) is already set but when you enter data into a form it allows you to enter all the data and only lets you know there is a duplicate ID when you try to save the record. Is there an instant way of letting a user know when they have entered a duplicate ID?

Tom
Apr 5 '07 #3
MMcCarthy
14,534 Expert Mod 8TB
The Indexed property to Yes (No Duplicates) is already set but when you enter data into a form it allows you to enter all the data and only lets you know there is a duplicate ID when you try to save the record. Is there an instant way of letting a user know when they have entered a duplicate ID?

Tom
In the After Update event of the ID textbox which I'm calling txtID ...
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtID_AfterUpdate()
  2.    If nz(DLookup("[ID]", "TableName", "[ID]=" & Me!txtID),0) <> 0 Then
  3.       Msgbox "This ID already exists", vbOKOnly
  4.    End If
  5. End Sub
  6.  
Mary
Apr 5 '07 #4
Well it worked, or thats what i thought to start with. If I put in a ID it warns me if it is in the table but then if i try to change the ID it continues to warn me that it already exists (even if it doesnt.

Very strange, Any ideas?
Apr 5 '07 #5
MMcCarthy
14,534 Expert Mod 8TB
Well it worked, or thats what i thought to start with. If I put in a ID it warns me if it is in the table but then if i try to change the ID it continues to warn me that it already exists (even if it doesnt.

Very strange, Any ideas?
Try this ...
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtID_AfterUpdate()
  2.    If nz(DLookup("[ID]", "TableName", "[ID]=" & Me!txtID),0) <> 0 Then
  3.       Msgbox "This ID already exists", vbOKOnly
  4.      Me!ID = Null
  5.    End If
  6. End Sub
  7.  
Mary
Apr 6 '07 #6
Im still getting the error message saying the ID already exists even if it doesn't. Im not sure if its checking the first number of the ID and if that number exists anywhere then its bringing up the message

e.g.

445959 is being checked against anything that has a 4 at the begining.

Im not really sure, i just dont understand why it isnt working.
Apr 11 '07 #7
MMcCarthy
14,534 Expert Mod 8TB
Try this ...
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtID_AfterUpdate()
  2. Dim tmpID As Long
  3.  
  4.    tmpID = nz(DLookup("[ID]", "TableName", "[ID]=" & Me!txtID),0)
  5.    If tmpID <> 0 Then
  6.         Msgbox "This ID already exists", vbOKOnly
  7.        Me!txtID = Null
  8.    End If
  9. End Sub
  10.  
IF this doesn't work there is something else going on.

Is your ID field a text field or and number field?


Mary
Apr 11 '07 #8
Yeay, it worked. Thanks for the help and your patience.

Tom
Apr 12 '07 #9
Yeay, it worked. Thanks for the help and your patience.

Tom
Sorry to bother you again, but i have a new problem. I need to be able to do the same thing as before but also check for letters as well as numbers becuase some of the ID's that im checking against also contain a mix of both.

Is it done in the same way?
Apr 17 '07 #10
hariharanmca
1,977 1GB
Sorry to bother you again, but i have a new problem. I need to be able to do the same thing as before but also check for letters as well as numbers becuase some of the ID's that im checking against also contain a mix of both.

Is it done in the same way?

why don't we go for a Qry

===================== QRY =======================

Expand|Select|Wrap|Line Numbers
  1. select * from TableName where FieldId in ( select distinct FieldId from TableName group by FieldId having Count(FieldId)>1)
Apr 17 '07 #11
MMcCarthy
14,534 Expert Mod 8TB
Sorry to bother you again, but i have a new problem. I need to be able to do the same thing as before but also check for letters as well as numbers becuase some of the ID's that im checking against also contain a mix of both.

Is it done in the same way?

Try this ...
Expand|Select|Wrap|Line Numbers
  1.    tmpID = nz(DLookup("[ID]", "TableName", "[ID]='" & Me!txtID & "'"),"")
  2.    If tmpID <> "" Then
  3.  
Mary
Apr 17 '07 #12
When running this code I get run time error 13 - Type Mismatch.

Hmmm maybe its worth me thinking about another way round this problem because im sure that we are running out of possible codes :)
Apr 18 '07 #13
MMcCarthy
14,534 Expert Mod 8TB
When running this code I get run time error 13 - Type Mismatch.

Hmmm maybe its worth me thinking about another way round this problem because im sure that we are running out of possible codes :)
ID and txtID are both text formats and not numbers, yes?
Apr 18 '07 #14
ID and txtID are both text formats and not numbers, yes?
Yes they are. Thats the reason I cant really understand why its not working.

Tom
Apr 18 '07 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: JJ | last post by:
What's best practise in this situation: Upon submitting data input on a detailsview (bound to an objectdatasource), I need to check for a duplicate email address (in an sql database) and present...
0
by: Nbene | last post by:
Hi All, Hoping someone can help with this one. I am opening a table and looping through the RecordSource (RcSr) of ! Email I am trying to add each email address to the string (strEmail) for...
2
by: oaklander | last post by:
I currently have two String variables I check to find if they are duplicates: String str1 = "red"; String str2 = "yellow"; if (str1.equals(str2)){ System.out.println("Duplicate"); }...
0
by: Gabriel Genellina | last post by:
En Fri, 18 Apr 2008 12:23:08 -0300, Shawn Milochik <Shawn@Milochik.comescribió: A dictionary with keys is perfectly reasonable. But a *list* of values has to be searched linearly for every...
7
by: john.cole | last post by:
I have searched all the groups I can, and I still haven't been able to come up the solution I need. I have the following problem. In my form named sbfrmSpoolList, I am entering a job, spool and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.