473,805 Members | 1,896 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Viewing duplicate entry

24 New Member
Hi,

I have a stock database and have recently solved an issue with duplication.

When a user enters a duplicate value in the 'DAMS_Number' field on a form, a message box alerts the user that the value already exists.

What I would like is for the form to display the corresponding record as soon as the user clicks 'Ok' on the message box.

The code I have for the duplicate alert (which I obtained from this site btw!) is as follows:

Expand|Select|Wrap|Line Numbers
  1. Private Sub DAMS_Number_AfterUpdate()
  2.  
  3. Dim tmpID As Long
  4.  
  5.    tmpID = Nz(DLookup("[DAMS Number]", "DAMS Stock", "[DAMS Number]=" & Me!DAMS_Number), 0)
  6.    If tmpID <> 0 Then
  7.         MsgBox "This DAMS asset already exists in the database", vbOKOnly
  8.    End If
  9.  
  10. End Sub
Can anybody help me with this?

Thanks!
Oct 9 '08 #1
36 2912
puppydogbuddy
1,923 Recognized Expert Top Contributor
Try replacing your code above with the following revised code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub DAMS_Number_AfterUpdate() 
  2.  
  3. Dim tmpID As Long 
  4.  
  5.    tmpID = Nz(DLookup("[DAMS Number]", "DAMS Stock", "[DAMS Number]=" & Me!DAMS_Number), 0) 
  6.    If tmpID <> 0 Then 
  7.         MsgBox "This DAMS asset already exists in the database", vbOKOnly 
  8.        Me.Filter = "[DAMS Number] = " & Me!DAMS_Number
  9.        Me.FilterOn = True
  10.    End If 
  11.  
  12. End Sub
Oct 9 '08 #2
ashenton
24 New Member
When I try the revised code I get this error:

Run-time error '3314':

The field 'DAMS Stock.Model' cannot contain a Null value because the Required property for this field is set to true. Enter a value in this field.


I need certain values to be entered when creating a new record where one does not exist, but having the Required property set to true results in the above error.

If I set all the Required properties to False, I get this error:

Run-time error '3022':

The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again.


The primary key is a field which is set to AutoNumber and has no real purpose other than to number each entry. The index for 'DAMS_Number' is set to 'Yes (No Duplicates) to prevent duplicate entries for the same asset.

Any ideas?
Oct 9 '08 #3
ashenton
24 New Member
Also, if I set the Index to Yes (Duplicates ok) I get a pop-up box asking for the 'DAMS_Number' value which I have just entered in the form. When I enter the value in the box and press enter it goes to the existing entry.

Having duplicates allow whilst it automatically notifies and takes the user to the corresponding record I can live with, but I really don't want the user to have to type the asset number in twice!
Oct 9 '08 #4
puppydogbuddy
1,923 Recognized Expert Top Contributor
please undo all the changes you made other than the changes I gave you.....otherwi se you will be giving me a moving target. The code I gave you should work (if you make the correction below) because it is in the same loop that generates the message box and uses the same criteria.

If you've made the correction and it still does not work, please post your code and provide details.....but do not make any other changes.


Just change this line:
Me.Filter = "[DAMS Number] = " & Me!DAMS_Number

To this:
Me.Filter = "[DAMS Number] = " & tmpID
Oct 9 '08 #5
ashenton
24 New Member
It still doesn't work. I've returned everything to how it was before you sent me the code (except the code of course!) and changed the line you specified.

Certain values are set to be required and the Required property of DAMS_Number is set to 'Yes (No Duplicates)'

The code now reads

Expand|Select|Wrap|Line Numbers
  1. Private Sub DAMS_Number_AfterUpdate()
  2.  
  3. Dim tmpID As Long
  4.  
  5.    tmpID = Nz(DLookup("[DAMS Number]", "DAMS Stock", "[DAMS Number]=" & Me!DAMS_Number), 0)
  6.    If tmpID <> 0 Then
  7.         MsgBox "This DAMS asset already exists in the database", vbOKOnly
  8.        Me.Filter = "[DAMS Number] = " & tmpID
  9.        Me.FilterOn = True
  10.    End If
  11.  
  12. End Sub
I still get run-time error 3314 after clicking 'ok' in the message box.

According to VB it is the line which contains 'Me.FilterOn = True' which is causing the issue (I'm guessing anyway as it is highlighted in yellow)
Oct 9 '08 #6
puppydogbuddy
1,923 Recognized Expert Top Contributor
I think all you need to do now is set the Required property of DAMS_Number to No. Is that a problem for you in terms of control? If it is, I will need to give you another method. Let me know.
Oct 9 '08 #7
ashenton
24 New Member
I set the required property for DAMS_Number to no but there are several other fields which are required (as well as DAMS_Number) which create the 3314 error.

DAMS_Number is the stock asset number and is required for more or less everything I do. It is the primary identifier on our stock so must be included in the database :)
Oct 9 '08 #8
puppydogbuddy
1,923 Recognized Expert Top Contributor
You should not have to set the required of any field other than the DAMS Number. We are only filtering on the DAMS number. What message did you get exactly?
Oct 9 '08 #9
puppydogbuddy
1,923 Recognized Expert Top Contributor
See if this works for you without changing the field settings that you had.
Expand|Select|Wrap|Line Numbers
  1. Private Sub DAMS_Number_AfterUpdate() 
  2.  
  3. Dim tmpID As Long 
  4. Dim strFilter As String
  5.  
  6. tmpID = Nz(DLookup("[DAMS Number]", "DAMS Stock", "[DAMS Number]=" & Me!DAMS_Number), 0) 
  7.    If tmpID <> 0 Then 
  8.         MsgBox "This DAMS asset already exists in the database", vbOKOnly 
  9.        strFilter = "[DAMS Number] = " & tmpID 
  10.        DoCmd.OpenForm Me, , , strFilter 
  11.    End If 
  12.  
  13. End Sub
Oct 9 '08 #10

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

Similar topics

3
3949
by: Mohammed Mazid | last post by:
Hi, Basically I have a problem with registering to my quiz system. I had borrowed some code from an existing program but I just do not know why it doesn't work. If (txtUsername = "" Or txtPassword = "") Or (txtFirstName = "" Or txtLastName = "") Then MsgBox "Please complete all the fields", vbCritical = vbOKOnly, "Incomplete Login Details"
1
14052
by: marx | last post by:
I have a bit of a problem and any help would be much appreciated. Problem: I have two dropdown list boxes with same data(all data driven). These are used for two separate entries. For every entry you cannot choose the same value twice. For example, I cannot choose for entry 1 the same value in both selection boxes (gqCategory1Entry1 and gqCategory2Entry1)
4
4390
by: sri2097 | last post by:
Hi all, I'm storing number of dictionary values into a file using the 'cPickle' module and then am retrieving it. The following is the code for it - # Code for storing the values in the file import cPickle book = {raw_input("Name: "): } file_object = file(database, 'w+') cPickle.dump(book, file_object)
1
6440
by: Joseph Chase | last post by:
I am running version 4.1.13a-log on a Mac XServe. How can I receive a 'duplicate entry' error for an UPDATE? An update isn't creating an entry, so why this error message? ____________________________________________________ 060427 11:57:23 Slave SQL thread initialized, starting replication in log 'kiosk1-bin.000006' at position 7233, relay log './royaldemo-2-relay-bin.000007' position: 7321 060427 11:57:23 Slave: Query caused...
5
3993
by: Manish | last post by:
The topic is related to MySQL database. Suppose a table "address" contains the following records ------------------------------------------------------- | name | address | phone | ------------------------------------------------------- | mr x | 8th lane | 124364 | | mr x | 6th lane | 435783 | | mrs x | 6th lane | 435783 |
8
3954
by: Iona | last post by:
Hi Allan, I'm using a nifty piece of code you put on here some time back to do a duplicate entry check as below. I'm using to check for duplicate names. However I am getting an error message on this line: Set rs = db.OpenRecordset("SELECT ID FROM Contacts WHERE (" & sWhere & ");") Contacts being the main table. I am using access 2003 The error message states that there are; Too few parameters. Expected 1 I have no idea how to...
5
23050
by: baur79 | last post by:
Hi guys i try to run this code in loop and to pass even the entry is duplicated def email_insert_in_db(email): sql="INSERT INTO emails (email) values ('%s') "%(email) db=_mysql.connect(host = "localhost", user = db_user, passwd = db_pass, db = db_name)
1
3395
by: chicago1985 | last post by:
I have a unique constraint in my Oracle table for 3 fields. If I enter duplicate info on the table using Oracle client I will get an Ora message error ORA-00001 that tells me it is a duplicate entry attempt. How do I capture that in my PHP page if someone tries to enter duplicate record info? My PHP Oracle insert statement in the action page: $s = OCIParse($c, "insert into tableOne values ('$varOne', '$varTwo', '$varThree')");...
4
4128
by: AXESMI59 | last post by:
have a project in which I am entering Serial Numbers and Date codes into a Combo box. Serial numbers are all different. However, they could each have the same Date Code. Each Serial Number has a corresponding Date Code which I then write to a table using VBA. When I try to enter a duplicate date code, it automatically finds the duplicate and will not allow me to add it again to that combo box. How do I configure that combo box so I can enter the...
0
9716
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10607
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10359
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10364
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9182
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7645
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6875
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5677
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4317
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.