473,387 Members | 1,569 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,387 software developers and data experts.

Just a warning on duplicate records

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 10145
MMcCarthy
14,534 Expert Mod 8TB
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,556 Expert Mod 16PB
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 Expert Mod 8TB
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,556 Expert Mod 16PB
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 Expert Mod 8TB
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
Thank you all, this solution works great.
Dec 5 '06 #7
MMcCarthy
14,534 Expert Mod 8TB
Thank you all, this solution works great.
You're welcome.
Dec 5 '06 #8
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
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
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...
6
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...
2
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...
0
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...
2
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...
4
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,...
2
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...
6
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...
1
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...

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.