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

Duplicate entry warning and display data

547 512MB
I have a problem with duplicate entries.
I can't get this code to work.
I have one other request.

When the message box appears, i would like the "racefinishtime" record in this same table to be displayed for this same "racetimingid" and equivalent "racenumber" previously added.
The Racedate is a unique field.
The addition of this duplicate record must not be blocked. I only want a warning messagebox to appear pls.
Is it Possible? Pls assist

Expand|Select|Wrap|Line Numbers
  1. Private Sub RaceNumber_BeforeUpdate(Cancel As Integer)
  2. Dim Answer As Variant
  3.  Answer = DLookup("[RaceNumber]", "RacetimingT", "[Racenumber] = " & Me.RaceNumber & " AND [RaceDate]= #" & Me.Racedate & "#")
  4. If Not IsNull(Answer) Then
  5.  MsgBox "You have entered a duplicate record for (this will appear now for this duplicate entry) Racenumber = 123 with  Racefinishtime = 16/11/2011 03:09:31 PM. " & vbCrLf & "Please press enter to continue and add the record and fix error afterwards.", vbCritical + vbOKOnly + vbDefaultButton1, "Duplicate"
  6. Cancel = True
  7. 'Me.Undo
  8. End If
  9. 'End Sub
Nov 16 '11 #1
2 3340
neelsfer
547 512MB
I got it working with this code after 4 hours of sweating
Expand|Select|Wrap|Line Numbers
  1. Private Function IsDuplicateRecord() As Boolean
  2.  
  3.     On Error Resume Next
  4.     Dim PreviousRecordID As Long
  5.     IsDuplicateRecord = False
  6.  
  7.     PreviousRecordID = 0
  8.     PreviousRecordID = DLookup("RacetimingId", "RacetimingT", "RacetimingId<>" & racetimingId & _
  9.     " AND RaceNumber=" & RaceNumber & " AND [RaceDate]= #" & Racedate & "#")
  10.     If PreviousRecordID <> 0 Then
  11.         MsgBox "You have entered this Racenumber twice. Please press ENTER to continue and make a note of this Race Number and finishtime to correct Race entry error later"
  12.         IsDuplicateRecord = True
  13.     End If
  14.  
  15. End Function
  16.  
Expand|Select|Wrap|Line Numbers
  1. On Error GoTo Form_BeforeUpdate_Err
  2. If IsDuplicateRecord Then Cancel = False
  3. Form_BeforeUpdate_Exit:
  4.     Exit Sub
  5.  
  6. Form_BeforeUpdate_Err:
  7.     MsgBox Error$
  8.     Resume Form_BeforeUpdate_Exit
i would still like to have the original Racenumber and it's RaceFinishtime displayed in this duplicate record messagebox
Any suggestions pls?
Nov 16 '11 #2
NeoPa
32,556 Expert Mod 16PB
If RaceDate is a unique ID then why do you use the following in your DLookup() code? :
Expand|Select|Wrap|Line Numbers
  1. "[Racenumber] = " & Me.RaceNumber & " AND [RaceDate]= #" & Me.Racedate & "#"
NB. Above SQL code is not appropriate for date checking. Americans get away with it if they don't have to export their databases but European dates will frequently fail with that code. See Literal DateTimes and Their Delimiters (#) for how it should be done properly.

DLookup() is fine for getting single field values but when it comes to accessing a whole record of data it starts to come unstuck. It's possible to set a criteria string and call DLookup() a number of times, but really you should be thinking of DAO (unless using ODBC or other non Access/Jet links then use ADODB) Recordsets instead.

What you want is perfectly possible, but the next step is yours.
Nov 17 '11 #3

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

Similar topics

0
by: Geetu | last post by:
I am trying to jar up a file and getting this exception, not sure what could be wrong. The same piece of code works fine in few machines but there is one machine where this piece of code gives this...
0
by: Gary Lundquest | last post by:
I have an application with MS Access 2000 as the front end and MySQL as the back end. All was well until I upgraded the MySQL (Linux) server. The Problem: I insert data into a cumulative table....
1
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? ...
8
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...
3
by: deepaks85 | last post by:
Dear Sir, I have setup a SQL database with PHP. Whenever I am trying to insert the data into my database it gives me error : 'Duplicate entry for key 2'. Please help me sir. I am sending you...
3
emandel
by: emandel | last post by:
In my DB I have an Events Table, a Participants table, and a attendance table. The attendance table is the junction table that connects the other two (many to many). So in the attendance tale, I...
5
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)...
1
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...
2
by: olcaygul | last post by:
hii i´m learning jsp and html with sql and i´m beginer on it, i have the table andcodes below in mysql and jsp, i´m working on html and jsp with netbeans IDE 3.6. of course if i try to insert any...
3
by: jacc14 | last post by:
Hi When I enter a job number i have set up the following Dim PID As String Dim stLinkCriteria As String Dim rsc As DAO.Recordset Set rsc = Me.RecordsetClone
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.