Hello everybody! this is my first thread here so lets hope im doing this right 
I have been a passive "member" now for a couple of months but now i have run in to a problem who I have not solved yet (stuck on the same issue now for a couple of days).
I think it is easy to solve but now i have been staring att this for so long time i have a hard time seeing the forest for all the trees if you know what i mean
I have a table that im modifying by using vba code.
I will use the table to plot a chart over the "gap" time between drifferent race cars.
So far i have the "delta time", the time that differs between the actual driver and the winner for every lap and i call this Gap. I want to add the gap times so that for example on lap 2 the total gap is gap for lap 1 + gap for lap 2 and so on to be able to plot how the gap is developing troughout the race.
Im trying to use Dlookup function to get the previous laps gap and add this to the actual gap post.
The Part of the code that I need help whith looks like this:
The issue now is that when i run this it writes the first drivers previous laps gap on every row in the actual lap. I realize that this is a bit fuzzy to understand so i will try to make a table to show...
And so on...
As you can see Bob is the winning driver and therefore he has 0 in gap trougout the race. Dave and Pete are on place 2nd and 3rd and they have a time gap.
What happens when I run it is:
I havent added the + current gap part in this draft of the code but that should be easy peasy
Hope that some of you have time to answer a lost newbie
Best Regards
Anders
I have been a passive "member" now for a couple of months but now i have run in to a problem who I have not solved yet (stuck on the same issue now for a couple of days).
I think it is easy to solve but now i have been staring att this for so long time i have a hard time seeing the forest for all the trees if you know what i mean
I have a table that im modifying by using vba code.
I will use the table to plot a chart over the "gap" time between drifferent race cars.
So far i have the "delta time", the time that differs between the actual driver and the winner for every lap and i call this Gap. I want to add the gap times so that for example on lap 2 the total gap is gap for lap 1 + gap for lap 2 and so on to be able to plot how the gap is developing troughout the race.
Im trying to use Dlookup function to get the previous laps gap and add this to the actual gap post.
The Part of the code that I need help whith looks like this:
Code:
Set db = CurrentDb()
Set Rst = db.OpenRecordset("GapAnalysis")
For x = 0 To Rst.RecordCount - 1
For m = 2 To Rst!MaxLaps
If Rst!Lap2 = 1 Then
Rst.Edit
Rst!Gap3 = Rst!Gap
Rst.Update
ElseIf Rst!Lap2 = [m] Then
Rst.Edit
Rst![Gap3] = DLookup("[Gap2]", "GapAnalysis", "Lap2 =" & m - 1 & "And [Driver] = [Förare] ")
Rst.Update
End If
Next m
Rst.MoveNext
Next x
The issue now is that when i run this it writes the first drivers previous laps gap on every row in the actual lap. I realize that this is a bit fuzzy to understand so i will try to make a table to show...
Code:
Lap Gap Driver Gap3
1 0 Bob Gap
1 4,54 Dave Gap
1 3,21 Pete Gap
2 0 Bob Gap(Lap = 2 ) + Gap(Lap = 1 And Driver = Bob)
2 7,89 Dave Gap(Lap = 2 ) + Gap(Lap = 1 And Driver = Dave)
2 2,67 Pete Gap(Lap = 2 ) + Gap(Lap = 1 And Driver = Pete)
3 0 Bob Gap(Lap = 3 ) + Gap(Lap = 2 And Driver = Bob)
3 8,93 Dave Gap(Lap = 3 ) + Gap(Lap = 2 And Driver = Bob)
3 1,76 Pete Gap(Lap = 3 ) + Gap(Lap = 2 And Driver = Bob)
And so on...
As you can see Bob is the winning driver and therefore he has 0 in gap trougout the race. Dave and Pete are on place 2nd and 3rd and they have a time gap.
What happens when I run it is:
Code:
Lap Gap Driver Gap3
1 0 Bob Gap
1 4,54 Dave Gap
1 3,21 Pete Gap
2 0 Bob Gap(Lap = 2 ) + Gap(Lap = 1 And Driver = Bob)
2 7,89 Dave Gap(Lap = 2 ) + Gap(Lap = 1 And Driver = Bob)
2 2,67 Pete Gap(Lap = 2 ) + Gap(Lap = 1 And Driver = Bob)
3 0 Bob Gap(Lap = 3 ) + Gap(Lap = 2 And Driver = Bob)
3 8,93 Dave Gap(Lap = 3 ) + Gap(Lap = 2 And Driver = Bob)
3 1,76 Pete Gap(Lap = 3 ) + Gap(Lap = 2 And Driver = Bob)
I havent added the + current gap part in this draft of the code but that should be easy peasy
Hope that some of you have time to answer a lost newbie
Best Regards
Anders
Last edited: