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 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. -
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,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.
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
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.
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
Thank you all, this solution works great.
MMcCarthy 14,534
Recognized Expert Moderator MVP
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 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...
|
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...
|
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...
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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: 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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |