473,545 Members | 2,042 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Just a warning on duplicate records

17 New Member
I am trying to set up a message box warning (or open to some sort of other warning) when a duplicate record is entered. I do want to allow duplicate records but I am looking to warn when it does occur.

Example of warning: Check number all ready entered are you sure you want to continue.

Any Ideas?
Dec 3 '06 #1
9 10160
MMcCarthy
14,534 Recognized Expert Moderator MVP
I am trying to set up a message box warning (or open to some sort of other warning) when a duplicate record is entered. I do want to allow duplicate records but I am looking to warn when it does occur.

Example of warning: Check number all ready entered are you sure you want to continue.

Any Ideas?
When relevant field is entered on form (lets call it RecNo for now) then you need a before update event to check if number is already entered.

Expand|Select|Wrap|Line Numbers
  1. Private Sub RecNo_BeforeUpdate()
  2. Dim rslt As Integer
  3.  
  4.    If nz(DLookup("[RecNo]", "TableName", "[RecNo]=" & Me.RecNo),0) <> 0 Then
  5.       rslt = Msgbox ("This number has already been entered. Do you wish to continue?", vbYesNo)
  6.       If rslt = vbNo Then
  7.          Me.RecNo = Null
  8.          Me.RecNo.SetFocus
  9.       End If
  10.    End If
  11.  
  12. End Sub
  13.  
Dec 3 '06 #2
NeoPa
32,563 Recognized Expert Moderator MVP
Mary's answer exactly matches the question.
However, in most circumstances you may be better served not entering a record number as such but allowing Access to supply an AutoNumber for the Primary Key. There are reasons why this is not always appropriate, but should always be considered.
Dec 3 '06 #3
MMcCarthy
14,534 Recognized Expert Moderator MVP
Mary's answer exactly matches the question.
However, in most circumstances you may be better served not entering a record number as such but allowing Access to supply an AutoNumber for the Primary Key. There are reasons why this is not always appropriate, but should always be considered.
This won't allow for duplicate entry Ade which seems to be a requirement.

Mary
Dec 4 '06 #4
NeoPa
32,563 Recognized Expert Moderator MVP
This won't allow for duplicate entry Ade which seems to be a requirement.

Mary
Quite right.
I must have misread it the first time because it states the requirement quite clearly. Sorry - ignore my post.
Dec 4 '06 #5
MMcCarthy
14,534 Recognized Expert Moderator MVP
Quite right.
I must have misread it the first time because it states the requirement quite clearly. Sorry - ignore my post.
Now Ade

I could never just ignore you. :D

Mary
Dec 4 '06 #6
jjstevens
17 New Member
Thank you all, this solution works great.
Dec 5 '06 #7
MMcCarthy
14,534 Recognized Expert Moderator MVP
Thank you all, this solution works great.
You're welcome.
Dec 5 '06 #8
BrerBunny
2 New Member
Hello,
I've tried adding this to my table to get it to flash up a warning for duplicate postcodes, but it doesn't work.

Is it because I'm using a string instead of a number?
The error message I get is Run Time error 3075:
Syntax error (missing operator) in query expression '[Postcode]=TN8 6HR'

my code is:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Postcode_BeforeUpdate(Cancel As Integer)
  2. Dim rslt As Integer
  3.  
  4.    If Nz(DLookup("[Postcode]", "Addresses", "[Postcode]=" & Me.Postcode), 0) <> 0 Then
  5.       rslt = MsgBox("This number has already been entered. Do you wish to continue?", vbYesNo)
  6.       If rslt = vbNo Then
  7.          Me.Postcode = Null
  8.          Me.Postcode.SetFocus
  9.       End If
  10.    End If
  11. End Sub
can you help?
btw, I entered it in on the form design screen under Events >> Before Update as an Event Procedure
Feb 15 '07 #9
BrerBunny
2 New Member
Hello,
I've tried adding this to my table to get it to flash up a warning for duplicate postcodes, but it doesn't work.

Is it because I'm using a string instead of a number?
The error message I get is Run Time error 3075:
Syntax error (missing operator) in query expression '[Postcode]=TN8 6HR'

my code is:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Postcode_BeforeUpdate(Cancel As Integer)
  2. Dim rslt As Integer
  3.  
  4.    If Nz(DLookup("[Postcode]", "Addresses", "[Postcode]=" & Me.Postcode), 0) <> 0 Then
  5.       rslt = MsgBox("This number has already been entered. Do you wish to continue?", vbYesNo)
  6.       If rslt = vbNo Then
  7.          Me.Postcode = Null
  8.          Me.Postcode.SetFocus
  9.       End If
  10.    End If
  11. End Sub
can you help?
btw, I entered it in on the form design screen under Events >> Before Update as an Event Procedure


looks like I should change this to:


Expand|Select|Wrap|Line Numbers
  1. Private Sub Postcode_BeforeUpdate(Cancel As Integer)
  2. Dim rslt As Integer
  3.  
  4.    If Nz(DLookup("[Postcode]", "Addresses", "[Postcode]='" & Me.Postcode & "'"), 0) <> 0 Then
  5.       rslt = MsgBox("This number has already been entered. Do you wish to continue?", vbYesNo)
  6.       If rslt = vbNo Then
  7.          Cancel = True
  8.          Me.Postcode.SetFocus
  9.       End If
  10.    End If
  11. End Sub
I'll try it and see!
Feb 15 '07 #10

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

Similar topics

1
4912
by: Peter | last post by:
My database has a text field "Registration" ~ it is the only Primary Key and no duplicates are possible. After you have entered all the fields for a new record you often find out that it is a duplicate when you try to save it. Has anyone got a code I can copy and use on the data entry form to produce a message box to warn that you are...
6
1813
by: Peter | last post by:
Can anyone advise me what is wrong with this code? I want it to tell me if I am entering a duplicate record. However, I always get the "Dupe" error message, whether I have entered a duplicate or not. The field REGISTRATION1 is in the form and Registration is the Control Source in the table (Can't remember why I named the two fields...
2
28866
by: Carroll | last post by:
I'm looking for a way in SQL to find duplicate records in a single table, that are the same based on 3 columns, regardless of what is in the other columns in the duplicate records. I would like to keep both records (or it could be more than 2 as well) where duplicate records are found. Also, I am interested in selecting all columns from the...
0
2097
by: B.N.Prabhu | last post by:
Hi, I have a DataTable with several rows. Its having 20 Columns. when i click the Insert button then i have to check the Database Rows. Whether these new rows are already available in the Database. If its there, then i need to seperate the Duplicate Records Based upon 4 columns(EmployeeID, ProjectName, ProjectType, StartTime -- should be...
2
2053
by: nethravathy | last post by:
Hi, The following table namely elcbtripselect contains 5147 records.I want to know wether this table contains duplicate records or not. I tried with following query 1)SELECT elcbtripselect.ELCBTRIP_voltsMIN, elcbtripselect.ELCBTRIP_voltsMAX, elcbtripselect.ELCBTrip_is_partwinding, elcbtripselect.ELCBTrip_is_ydelta,...
4
4185
by: Thomas Arthur Seidel | last post by:
Hello to all, I have a small or big problem with a customer data base, where during a change of system we might have created duplicate records. This should be easy to find, you might think, but, we are talking about roughly 10000 records or less in a total volume of 1 MIO records or more. I have considered a strategy: The station ID and a...
2
3999
by: nomvula | last post by:
hi guys i need some help to duplicate records on my form datasheet: here's the example of my form results: ClientLookup DateCaptured ForecastDate Description ForecastQuantity Forecast Actual UJ 18-Apr-08 01-Mar-08 Fees: Asset 1 R 31,200.00 R 31,200.00 NMBM 22-Apr-08 23-Mar-08 P-MI (E) 07/2006 3 R 47,485 R 38,849 i have 200 records deplayed...
6
5921
by: Dilip1983 | last post by:
Hi All, I want to delete duplicate records from a large table. There is one index(INDEX_U1) on 4 columns(col1,col2,col3,col4) which is in unusable state. First of all when i tried to rebuild index it showed error as unique key violation. So i want to delete duplicate records for col1,col2,col3,col4 combination. How can i delete the...
1
7253
by: xraive | last post by:
I have a problem with this. Currently I am trying Allen's code and i am not successful. Current Design Table1 (Main Form) TravelID (PK) ApprovedBY EntreredBy BudgetCode ExpenseCode
0
7478
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...
0
7923
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...
1
7437
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...
0
7773
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5984
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...
0
3466
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1901
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
1
1025
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.