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
14 2009
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
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
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 ... -
Private Sub txtID_AfterUpdate()
-
If nz(DLookup("[ID]", "TableName", "[ID]=" & Me!txtID),0) <> 0 Then
-
Msgbox "This ID already exists", vbOKOnly
-
End If
-
End Sub
-
Mary
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?
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 ... -
Private Sub txtID_AfterUpdate()
-
If nz(DLookup("[ID]", "TableName", "[ID]=" & Me!txtID),0) <> 0 Then
-
Msgbox "This ID already exists", vbOKOnly
-
Me!ID = Null
-
End If
-
End Sub
-
Mary
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.
Try this ... -
Private Sub txtID_AfterUpdate()
-
Dim tmpID As Long
-
-
tmpID = nz(DLookup("[ID]", "TableName", "[ID]=" & Me!txtID),0)
-
If tmpID <> 0 Then
-
Msgbox "This ID already exists", vbOKOnly
-
Me!txtID = Null
-
End If
-
End Sub
-
IF this doesn't work there is something else going on.
Is your ID field a text field or and number field?
Mary
Yeay, it worked. Thanks for the help and your patience.
Tom
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?
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 ======================= - select * from TableName where FieldId in ( select distinct FieldId from TableName group by FieldId having Count(FieldId)>1)
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 ... -
tmpID = nz(DLookup("[ID]", "TableName", "[ID]='" & Me!txtID & "'"),"")
-
If tmpID <> "" Then
-
Mary
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 :)
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?
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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");
}...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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,...
|
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...
| |