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

How to KEEP the last record but delete previous duplicates in A2007

547 512MB
I have a race timing program.
In certain races, a team of 2 cyclists may ride together as a team.
Both persons will be timed, but only the last person crossing the line's time, must be kept in the database. The first person crossing the line, must be deleted as a duplicate record, if person crosses within 10 min of the last person.

i have tried the following but is stuck now.
Expand|Select|Wrap|Line Numbers
  1. Dim rs1 As Recordset
  2. Dim myRaceTime As Date, myRaceNo As String, x As Long
  3. Set rs1 = CurrentDb.OpenRecordset("RacetimingT", dbOpenDynaset)
  4.  
  5. x = 0
  6. rs1.MoveLast
  7. With rs1
  8.     Do Until .EOF
  9.         myRaceNo = !RaceNumber   'racenumber is a numberfield type and of a cyclist
  10.         myRaceTime = !RaceFinishTime  'the finish time of the cyclists
  11.         .MoveNext
  12.             Do Until .EOF
  13.                     If (!RaceNumber = myRaceNo) And _
  14.                         (DateDiff("n", myRaceTime, !RaceFinishTime) > -10 And _
  15.                         DateDiff("n", myRaceTime, !RaceFinishTime) < 10) Then
  16.                             .delete
  17.                     End If
  18.                         .MoveNext
  19.             Loop
  20.                 .MoveLast
  21.                 x = x + 1
  22.                 .Move x
  23.     Loop
  24. End With
  25. rs1.close
  26. Set rs1 = Nothing
  27.  
  28.  
  29.  End With
Any suggestions please?

Attached Images
File Type: jpg deleted first record.jpg (97.0 KB, 243 views)
Nov 3 '13 #1

✓ answered by NeoPa

In my previous posting the actual finish time is in a field called Racefinishtime
I'm sure you're right Neels, but I'd rather have such important information expressed clearly in the question than have to dig through various bits of code to find it for myself. That's a very important point to consider when posting future questions, of course. We have it now anyway, so all is good.

One specific point isn't too clear yet though :
You refer to a contestant's RaceNumber being scanned multiple times. From this I deduce that a contestant, in your terminology, is a team rather than an individual racer. Is that correct? I will proceed as if it is for now.

From your posted code (which seems to remove all records within 3 minutes either way BTW - not just records up to 3 minutes afterwards), if you remove the effect of line #14 and convert the check to use -10 instead of -3, it should do what you need.

In SQL, you might want something like :
Expand|Select|Wrap|Line Numbers
  1. DELETE
  2. FROM   [RaceTimingT] AS [tRT]
  3. WHERE  ([RaceTimingID] In(SELECT DISTINCT
  4.                                  tRT1.RaceTimingID
  5.                           FROM   [RaceTimingT] AS [tRT1]
  6.                                  INNER JOIN
  7.                                  [RaceTimingT] AS [tRT2]
  8.                             ON   tRT1.RaceName=tRT2.RaceName
  9.                            AND   tRT1.RaceNumber=tRT2.RaceNumber
  10.                           WHERE  (tRT1.RaceFinishTime<tRT2.RaceFinishTime)
  11.                             AND  (DateAdd('n',10,tRT1.RaceFinishTime)>=tRT2.RaceFinishTime))
NB. If you don't want to suffer from any awkward rounding issues with timings, and comparisons thereof, I recommend you use DateAdd(), as I have in my example, rather than DateDiff().

5 1302
NeoPa
32,556 Expert Mod 16PB
Neels, may I ask why the slower time only is recorded?
Nov 3 '13 #2
neelsfer
547 512MB
Neopa
We have teams of 2 persons cycling together in a special type of mountain bike races called stage racing (almost like the Tour de France) , and they are suppose to finish together, not more than 2 min apart. This is normal practice then to keep the 2nd person's finish time for the reporting. In normal races everybody finishes in their own time with only one result.
I have sql code that works in a query, but it deletes anything before the last person and not within a specified time.
Expand|Select|Wrap|Line Numbers
  1. DELETE racetimingT.racetimingID, racetimingT.RaceNumber
  2. FROM racetimingT
  3. WHERE (((racetimingT.racetimingID)<>(SELECT Max(racetimingid) AS MaxOfracetimingid FROM racetimingt AS Dupe      
  4.    WHERE (Dupe.racenumber = racetimingT.Racenumber)      
  5.   and (Dupe.racename = racetimingT.Racename)                    
  6.    AND (Dupe.racenumber = RacetimingT.racenumber))));
  7.  
Nov 3 '13 #3
NeoPa
32,556 Expert Mod 16PB
Thank you. That puts the question into context at least :-)

From your posted SQL I'm assuming the important data is all found within table [RaceTimingT]. There appear to be three fields ([RaceName], [RaceNumber] & [RaceTimingID]) but it isn't clear to me, without the experience in racing, what they refer to. I might guess that the [RaceName] identifies the race itself; The [RaceNumber] idenifies a contestant or team & the [RaceTimingID] identifies the record where a time is logged. There appears to be nothing which indicates what the actual time is though. This seems to be important information, without which it's impossible to determine which records are the quicker times and whether they fall within the ten minute window or not.

Am I close to understanding this question at all?
Nov 4 '13 #4
neelsfer
547 512MB
Hi Neopa
In my previous posting the actual finish time is in a field called Racefinishtime and it is = now() and the RaceNumber is a unique number for the contestant and as you correctly noticed the RaceName is the specific event.
The code below is from another form where the first record is kept, and all subsequent duplicate records are deleted within 3 minutes of the first record. I want to achieve the REVERSE of that now.
(with the code i mentioned now, i use a RFID reader which scan a chip with the contestants Racenumber on it multiple times, and only the first record must be kept)
Expand|Select|Wrap|Line Numbers
  1. Dim rs1 As Recordset
  2. Dim myRaceTime As Date, myRaceNo As String, x As Long
  3. Set rs1 = CurrentDb.OpenRecordset("RaceEntry2", dbOpenDynaset)
  4. x = 0
  5. rs1.MoveFirst
  6. With rs1
  7.     Do Until .EOF
  8.         myRaceNo = !RaceNumber   'racenumber is a numberfield type
  9.         myRaceTime = !RacefinishTime
  10.         .MoveNext
  11.             Do Until .EOF
  12.                     If (!RaceNumber = myRaceNo) And _
  13.                         (DateDiff("n", myRaceTime, !RacefinishTime) > -3 And _
  14.                         DateDiff("n", myRaceTime, !RacefinishTime) < 3) Then
  15.                             .delete
  16.                     End If
  17.                         .MoveNext
  18.             Loop
  19.                 .MoveFirst
  20.                 x = x + 1
  21.                 .Move x
  22.     Loop
  23. End With
  24. rs1.close
  25. Set rs1 = Nothing
Hope it is more clearer now
Nov 4 '13 #5
NeoPa
32,556 Expert Mod 16PB
In my previous posting the actual finish time is in a field called Racefinishtime
I'm sure you're right Neels, but I'd rather have such important information expressed clearly in the question than have to dig through various bits of code to find it for myself. That's a very important point to consider when posting future questions, of course. We have it now anyway, so all is good.

One specific point isn't too clear yet though :
You refer to a contestant's RaceNumber being scanned multiple times. From this I deduce that a contestant, in your terminology, is a team rather than an individual racer. Is that correct? I will proceed as if it is for now.

From your posted code (which seems to remove all records within 3 minutes either way BTW - not just records up to 3 minutes afterwards), if you remove the effect of line #14 and convert the check to use -10 instead of -3, it should do what you need.

In SQL, you might want something like :
Expand|Select|Wrap|Line Numbers
  1. DELETE
  2. FROM   [RaceTimingT] AS [tRT]
  3. WHERE  ([RaceTimingID] In(SELECT DISTINCT
  4.                                  tRT1.RaceTimingID
  5.                           FROM   [RaceTimingT] AS [tRT1]
  6.                                  INNER JOIN
  7.                                  [RaceTimingT] AS [tRT2]
  8.                             ON   tRT1.RaceName=tRT2.RaceName
  9.                            AND   tRT1.RaceNumber=tRT2.RaceNumber
  10.                           WHERE  (tRT1.RaceFinishTime<tRT2.RaceFinishTime)
  11.                             AND  (DateAdd('n',10,tRT1.RaceFinishTime)>=tRT2.RaceFinishTime))
NB. If you don't want to suffer from any awkward rounding issues with timings, and comparisons thereof, I recommend you use DateAdd(), as I have in my example, rather than DateDiff().
Nov 5 '13 #6

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

Similar topics

10
by: Alain Guichaoua | last post by:
Good evening to all Here is my problem : I have a form with a subform. They are linked. When I open the form I would like the subform to reach its last record. I tried the method...
2
by: Robert | last post by:
I have a label on my form lblCount and the following code in my form for displaying a record count: Private Sub Form_Current() Me.RecordsetClone.Bookmark = Me.Bookmark Me!lblCount.Caption =...
2
by: Anand Ganesh | last post by:
Hi All, How to Implement Move Next, Move Previous, Last Record and First Record in a DataGrid Control ? Is there any standard tool available in the tool box button? Thanks for your time. ...
5
by: Bronislav | last post by:
I have an error when I try to delete last record in the record set. The code I'm using is: lcurrow = Me.BindingContext(DsTextProdMain, "TextProductsMain").Current lcurrow.Delete() This code...
2
by: ahmedlasheen | last post by:
hello every body when iam trying to delete the last record in DGV this erro appears "Input string was not in a correct format." this error appears only when i am trying to delete the last record....
4
by: gimme_this_gimme_that | last post by:
Is there a way to get the last day of the previous business quarter from DB2? For 10/21/2008 the day would be 9/30/2008. Thanks.
4
by: steve75043 | last post by:
Hello I hope someone can help with this. I need to subtract dates in current record from previous record for the current store. The key fields in the form are customer, store number and date picked...
0
by: praka88 | last post by:
I am a student and I need to develop a project using vb6.0 as front end and oracle as back end . how to solve a fetch the previous and last record in oracle using v b6.0
1
by: dekk | last post by:
Hi, Thanks for viewing this post. I have a subform called 'Time' that captures alot of time activity by day. Two of my fields are 'StartTime' and 'EndTime' I would like to increment the...
1
LeighW
by: LeighW | last post by:
Hello, I used Allen Browne's method of assigning default values from the last record which is especially helpful when adding a new record to filtered records. Using his method I had to create a...
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: 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: 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
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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...

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.