How Can I Check For Duplicate Entries After Leaving A Field?
Aug 30, 2005
I'm pretty new to Access, so please overlook any stupid questions :)
I have a data entry form that has one field that cannot be a duplicate. So, in the table I have it Indexed with No duplicates.
The problem is that the form doesn't notify the user that they have entered duplicate information until they close the form. So the 10 minutes they spent filling it out is wasted.
So, after consulting various posts, I did a BeforeUpdate event with the following code:
(the field that must be unique is called "LS Number", in the form "Q and D" based on the table "Q and D Database")
Private Sub LS_Number_BeforeUpdate(Cancel As Integer)
On Error GoTo LS_Number_BeforeUpdate_Err
If (DLookup("[LS Number]", "Q and D Database", "[LS Number]=Forms![Q and D]![LS Number]")) Then
MsgBox "The LS Number you entered already exists. Enter a unique LS Number", vbInformation, "Duplicate LS Number"
When I test this by entering a duplicate LS Number, it gives me the error "Type Mismatch." Unfortunately, I have no idea what this means, nor do I know how to fix it.
I have a problem where in a table called tblPatientLanguage that contains three fields
PatientLanguageID PatientID LanguageID
a patient who is identified by PatientID can speak several languages identified by the LanguageID.
The problem is with my current form and code
For Each varSelected In Me!lstLanguage.ItemsSelected rs.AddNew rs("PatientID") = [Forms]![frmPatientDemographics]![PatientID] rs("LanguageID") = Me!lstLanguage.ItemData(varSelected) rs.Update Next varSelected
when the user click on the command button called cmdOK it will put the data in the table "tblPatientLanguage" and corresponding fields. without checking to see if there is already a duplicate languageID that corresponds to the same patientID in the table
This has lead to duplicates in the table
example PatientID = 9
if I look in the table I will see 7 entries that say
PatientID = 9 and LangaugeID = 7
I want to prevent this from happening with and if statement I could make both the PatientID and LanguageID primary keys this would prevent this from happening. But I would rather do it in the VBA code? This way in will move thorugh the selections without poping an error and the person inputing the date. Any ideas sorry for being long winded. I attached the database.
PS. If looking at the database you have to use form frmPatientDemographics and click on the language link
I have a form that allows users to search the database for records based on there criteria. The form allows the user to search, through combo boxes, by variables. The first is MAT, the second is Relocation Area. The search works fine when the user selects options form the combo boxes. However sometimes it is neccesary to leave the location field blank and only search by MAT. When the location combo box is left blank no records are found. Is there anyway around this. The SQL code for the query is below:
SELECT [Extract Data].[ID], [Extract Data].AREA, [Extract Data].[MAT], [Extract Data].[Relocation Area 1], [Extract Data].[Relocation Area 2], [Extract Data].[Relocation Area 3], [Extract Data].[Grade Score] FROM [Extract Data] WHERE ((([Extract Data].[MAT])>forms![Data Search]!SearchMAT) And (([Extract Data].[Relocation Area 1])=Forms![Data Search]!SearchArea)) Or ((([Extract Data].[MAT])>Forms![Data Search]!SearchMAT) And (([Extract Data].[Relocation Area 2])=Forms![Data Search]!SearchArea)) Or ((([Extract Data].[MAT])>>Forms![Data Search]!SearchMAT) And (([Extract Data].[Relocation Area 3])=Forms![Data Search]!SearchArea));
I have a table that contains doctor information including their license number. This came from a worksheet that tracked referrals from last season. I need a query that will show me only those record that have a unique MD License number. In other words I only need to see the 5-600 doctors out of the 2420 referrals in the table. Once I get the query of unique MD's I can create a report for the salesmen to use to contact them for the upcoming year. I know this is probably simple but I can't find the solution. Thanks in advance.
I have a simple database that I put my execptions in for the day for scanning. Is there a way that my serial field on my forum can check to see if someone already scanned that serial for that day using the "On Lost Focus" event.
I have an application that enters candidates in, who apply for a job.
I found that I can enter a candidate in, and if I dont enter at least an address type or phone type ( giving that candidate an address record, albiet a blank one (just a type of address) and a phone record) then the candidate wont have a sub record for addres or phone at all.
This is hurting my reports. They are set to pull the primary address and phone only, as we dont need to have 2-3 contact information for a candidate on a report This is how I found out that I had blank address and phone for some test records. I need to be able to check when a person does a number of things, that at least the combos for phone type and address type have been chosen as something. This will ensure that they have a primary address and phone, as I have code that takes care of all that. I tried putting the following code in the form's before update, but since it is calling to a subform, the minute I tab TO the address combo, I get the message. The form is updating before I get the chance to skip the field.
Here is the lay out. A user can enter in candidate, their address, phone, application and activities. Address, phone, applications and activities are all sub reports on a tab control. The user should be able to move freely within any record, and only be bothered when they try to leave, if important information is still empty. I dont want to control how they enter ('you must enter this first!' lol) just that they do enter it in the end.
What I want to do is check when the user is leaving a record.(closing form, going to another record, clicking the search button that opens another form etc) if either combo is empty (no primary contact info) then it gives the message and goes back to the combo that is empty.
Here is the code I have. If anyone can help me find the right place to put it, I would really appreciate it. Thank you,
If IsNull(Me.[subAddressEntry].Form![cmbAddressTypeID]) Then msgbox "You must enter an Address" Me.[subAddressEntry].Form![cmbAddressTypeID].SetFocus Cancel = True ElseIf IsNull(Me.[subPhoneEntry].Form![cmbPhoneTypeID]) Then msgbox "You must enter a Phone" Me.[subPhoneEntry].Form![cmbPhoneTypeID].SetFocus Cancel = True Else: Cancel = False End If
If I can't figure this out, I am thinking of making a new address type and phone type. Call it "none chosen" and then make that a default selection. Then one would always be chosen...I think. I would like to avoid that though.
I have a downtime database that tracks units down, time on, reason down, etc. When a unit goes down, I log the name of the unit and the time down in separate fields. When a unit goes back on line, I log the time on and the reason in separate fields. All this is in a form. When the unit goes on line, I want the user to be forced to enter a reason only after he has entered a time on, not before. The “reason” field must be left blank until the unit is on. How do I do that? I have searched the forum for this and have not found leaving a field blank based on another field’s data. I will supply whatever you need to help me. Thank you.
I have a database where I have a number from a client. We copy/paste it from a pdf file. The number has dots in it (1.00.00.000). I would like to create a solution that when I paste the number in the field and go to the next field, it will take out the dots from the number.
I have a form for rentals where I have fields for car details and for client details. I have a list box for clients so that when I enter the Client Id I automatically get all the records filled out on the form, from the clients table...
This works but the problem is that sometimes I have a new client who rents a car that is not on the database so I insert the client details manually on the rentals form without filling in the client ID as this client does not exist on the database.
The problem comes when I want to save the form it wont allow me to leave the client ID field blank... I imagine this is because of the relationship...
hello, Currently i have a database that holds information about computers. Each computer has a Service tag and is associated to a person. I need to be able to prevent duplicate service tags from being entered. I am using indexing and don't allow duplicates from the table design view. But, if a duplicate service tag is indeed entered, i want to inform the user who that service tag currently belongs too without having to search through the DB manually. I need then to give the user the option to delete the duplicated record they just entered or change the service tag that they just entered. Thanks. Jared
I've set up a booking system and am looking to stop the system recording double bookings.
I've 3 fields, RoomID, Date and Time that need to be searched, however I can't just simply set the properties to No Duplicates (as this would mean a booking cannot be made on the same day at 9:00 and 12:00 for example).
I am running a query to find out duplicate in two fields in one table. Postcode and Address Line 1. Can anyone tell me the formula for only picking up the first 6 charaters in the Address Line 1 field??? I cant remember how to do it!
I am using information pulled from a separate database to create a new database for mail merger purposes. I have created delete queries that go out and delete specific records from the new database to help us get the proper list before setting up the mail merge. However, now I am stuck. We have customers that have multiple accounts with us that are qualified for this mailing, yet each customer needs to receive only one mailing. The table looks like this essentially. Table 1id statCode acct custNumber* addy-etc. *This is the field in which we can find exact duplicates. What I need to do is remove the duplicate entries and leave at least one of the entries within the table. It does in fact need to remove the whole record, but as I said leave at least one of the records behind. Can someone please help me to find a solution to this. I guess I should add that I am not very good with Access and I use it very sparingly. I assume that the above can be accomplished using a SQL statement. Any help will be greatly appreciated. LR**EDIT** I also needed to add that I do need to exclude 000 00 0000 from being removed because of duplication.
Hi all, I am currently using this code in the before Update event of the Surname Textbox on a form. The first Textbox is FirstName. The second one is Surname.
If (Not IsNull(DLookup("[FirstName]", _ "Employee", "[FirstName] ='" _ & Me!FirstName & "'"))) And (Not IsNull(DLookup("[Surname]", _ "Employee", "[Surname] ='" _ & Me!Surname & "'"))) Then MsgBox "Someone already exists with the same name! Please check for duplicates", vbCritical, "IPDMS" Me.Undo End If
However once the user has entered the surname and tries to save the record the MsgBox is coming up. Basically what is happening is the first name is coming up as the duplicate entry only. I need to prevent the whole name (first name and surname together) from being duplicated.
I have a booking form database With a date field. I want users to be warned when they try to enter a date that already exists in the database in order to avoid double booking:confused: .....
I'm new to using VBA for MS Access. May I enlist your help, Please.
I'm working on a human resources database for a group of employees. I'm trying to automate their login process after they have opened the database so that each employee's privacy is respected. Using an initial form, employees are separated into "New User" or "Returning User". My problem concerns setting up the "New User" in the database.
The New User is directed to form "frm_NU". The form has several unbound fields which are later carried to the table "tbl_Employees". Two of the fields on the form are used to create the EmployeeID. Those are Initials [INI] and Phone Extension [EXT]. The EmployeeID will be used in a filter so that only that employee's information is made available to the user (simulated Privacy).
Because the employees are unfamiliar with MS Access and its cryptic error messages, I need to create a message box which will give a plain English warning when a user attempts to use an existing ID to create a new record. [EmployeeID] is a field in the table. it is set as a key and does not allow duplicates.
When a new user enters his/her initials and phone extension I want the new ID to be compared to the table and if found, a message should appear. This is a preemptive strike to prevent the user from getting to the more cryptic MS Access error message.
I've tried using Dlookup and Dcount to try to pass some meaningful data to the If statement variable VarX to trigger the message box; assuming that Varx should be something other than Null or Empty
If VarX <Is Not Empty> Then X = MsgBox("Another record already exists by that name", vbOKOnly) Else Y = MsgBox("Passed", vbOKOnly) End If
I keep getting an error at the DLookup formula or DCount formula saying: Run-time error; 2001 You canceled the previous operation. It also appears that the DLookup never looks up anything nor does DCount count anything even though I'm purposely entering duplicate information which exists in "qry_Employees". I was expecting VarX to be either the duplicate ID or a record number or record count or something.
sorry to bother everyone again, this is such a great forum, and ive gotten soo much help here.
i have a customer table, containing custRef, custName, drawerRef, Address, Phone, Fax
now it contains site addresses so the custName can be the same for quite a number of entries. no the combo box in my form obviously shows all entries for custName which means the same name repeated sometimes 6 or 7 times, as i only need to select one, is there a way without looking to different tables etc to just show unique entries. i dont want to list them all in another table because i dont know them all yet, so i want it to lookup the list as i enter them.
Hi, I have a rather large database that was built in Access '97 and recently converted to 2003. I have a couple problems now. I get an error message about not being able to update the form because it would create a duplicate value in the primary key, index, or relationship. (Error 3022) I didn't build this particular database so I'm not totally sure why somethings are done the way they are. I've spent a long time going through everything to try to understand the relationships and I've asked lots of people at work to look at it, but no one seems to understand why it's doing what it's doing. The Access Help information has helped me understand some things better, but not this problem. I've gone through every table and removed all primary keys and set all indexes to allow duplicates. Then, when I was looking at the relationships and object dependancies, I think everything looks to be in order. However, when i add info directly to the table instead of using the form, the form is not updated with the new info. the table keeps the information, but isn't communicating with the form and i suspect reverse is true which is where the error is coming from. But how do I detect that for sure and how can I fix it with out starting over? I've gone through and added data to one field in the form at a time to try and narrow down what field is causing the problem, but no matter what i get the same error. Is there a way to find out exactly what field is causing the error? Thanks for any help you can offer!
I'm aware of the wizard in MS Access that creates a new table containing duplicated entries that have been entered under one column, however, my problem is slightly more complex...
A contractor of mine has recorded information from CCTV surveys of sewers (not very glamorous I know!) in a Microsoft Access database. If you can imagine - the camera can be pushed along a pipe from both ends. Sometimes, the survey is abandoned in one direction and then repeated along the same length of pipe but from the other direction. The database contains (amongst other columns) a "start manhole" reference and a "end manhole" reference. eg:
16014
As you can see, the information contained by both entries will be the same (as they are the same length of pipe). Therefore, I was wondering how I could get MS Access to: 1. Recognise these 2 entries as duplicates 2. Create a table that hides the duplicated entry with a shorter "SectionLength" value.
I'm using a pretty simple inner join on two tables but the some of the same results are showing up twice. If I just remove the inner join all the results are uniquely present. For some reason the inner join creates about 10% more records that are all duplicate entries. Any idea what might cause this? :confused:SELECT products.product_nameFROM products INNER JOIN categories ON products.category = categories.category_nameWHERE ((products.X)=True);
I am trying to get a 2nd combo working from the first .
I have a table called Keystage (tblKeystage) and I have also named my 1st combo cboKeystage. then by following the vba below I created another 6 tables with corresponding names and combo's.
Private Sub cboKeystage_AfterUpdate()
On Error Resume Next
Select Case cboKeystage.Value Case "Foundation" cboYear.RowSource = "tblFoundation" Case "KS1" cboYear.RowSource = "tblKSOne" Case "KS2" cboYear.RowSource = "tblKSTwo" Case "KS3" cboYear.RowSource = "tblKSThree" Case "KS4" cboYear.RowSource = "tblKSFour" Case "Post16" cboYear.RowSource = "tblPost"
End Select
End Sub
The combo boxes both work, brilliant. My problem is that when I enter another record and make a selection from the 1st combo box, it changes all the records.
I have imported a table from Excel. The table contains a long list of names and there are quite a lot of duplicates. How do I remove the duplicates so I can import the clean list into a value list in Access ?
I'm trying to use access to identify how many times an indiviual appears in my database. I've got a large file which gives me all referrals, each referral comes with two identifiers, one unique to the person, another unique to the referral. This means that the person unique number may be repeated multiple times (if a person has more than one referral) but the referral number would be different each time.
I've run a query to identify the duplicates, i.e. the records where the person unique identifier is repeated. What I am trying to do is work out now how many people have been referred twice, how many three times etc. The original query looks something like this (but on a much bigger scale).
Person Referral 1 A 1 B 1 C 2 D 2 E 3 F 3 G 3 H
What I'm after is a query that will tell me that two people were referred three times (1 and 3) and that one was referred twice (2) and so on.