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?
9 10145
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. -
Private Sub RecNo_BeforeUpdate()
-
Dim rslt As Integer
-
-
If nz(DLookup("[RecNo]", "TableName", "[RecNo]=" & Me.RecNo),0) <> 0 Then
-
rslt = Msgbox ("This number has already been entered. Do you wish to continue?", vbYesNo)
-
If rslt = vbNo Then
-
Me.RecNo = Null
-
Me.RecNo.SetFocus
-
End If
-
End If
-
-
End Sub
-
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.
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
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.
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
Thank you all, this solution works great.
Thank you all, this solution works great.
You're welcome.
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: - Private Sub Postcode_BeforeUpdate(Cancel As Integer)
-
Dim rslt As Integer
-
-
If Nz(DLookup("[Postcode]", "Addresses", "[Postcode]=" & Me.Postcode), 0) <> 0 Then
-
rslt = MsgBox("This number has already been entered. Do you wish to continue?", vbYesNo)
-
If rslt = vbNo Then
-
Me.Postcode = Null
-
Me.Postcode.SetFocus
-
End If
-
End If
-
End Sub
can you help?
btw, I entered it in on the form design screen under Events >> Before Update as an Event Procedure
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: - Private Sub Postcode_BeforeUpdate(Cancel As Integer)
-
Dim rslt As Integer
-
-
If Nz(DLookup("[Postcode]", "Addresses", "[Postcode]=" & Me.Postcode), 0) <> 0 Then
-
rslt = MsgBox("This number has already been entered. Do you wish to continue?", vbYesNo)
-
If rslt = vbNo Then
-
Me.Postcode = Null
-
Me.Postcode.SetFocus
-
End If
-
End If
-
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: - Private Sub Postcode_BeforeUpdate(Cancel As Integer)
-
Dim rslt As Integer
-
-
If Nz(DLookup("[Postcode]", "Addresses", "[Postcode]='" & Me.Postcode & "'"), 0) <> 0 Then
-
rslt = MsgBox("This number has already been entered. Do you wish to continue?", vbYesNo)
-
If rslt = vbNo Then
-
Cancel = True
-
Me.Postcode.SetFocus
-
End If
-
End If
-
End Sub
I'll try it and see!
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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: 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,...
| |