Results 1 to 3 of 3
  1. #1
    Martin001 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    2

    Calculating vehicle individual journey mileage over a given time

    Hi
    Here is a query I have produced from a vehicle tracker database table. What I want to do is to calculate mileage of each journey over a time period based on the start and stop in the reason field. I have highlighted what I want in the calc field, so I know the mileage of each journey taken. Can anyone help I have no idea how the achieve this.
    Thanks
    Martin



    Vehicle
    Time_Date
    Street Name
    Distance (mi)
    Reason
    Calc Field
    xxxxxx 06/05/14 17:08:20
    0
    Ignition On
    xxxxxx 06/05/14 17:08:31
    0
    Start
    xxxxxx 06/05/14 17:08:59
    0.2
    Error report
    xxxxxx 06/05/14 17:09:54
    0.2
    Time Send
    xxxxxx 06/05/14 17:10:54
    0.5
    Time Send
    xxxxxx 06/05/14 17:38:57
    0.4
    Time Send
    xxxxxx 06/05/14 17:39:23
    0
    Ignition Off
    xxxxxx 06/05/14 17:39:23
    0
    Stop 1.3
    xxxxxx 06/05/14 17:39:23
    0.1
    Acc. Summary
    xxxxxx 06/05/14 17:39:23
    0
    Bus Ignition Off
    xxxxxx 06/05/14 17:50:35
    0
    Wakeup
    xxxxxx 07/05/14 17:07:19
    0
    Bus Ignition On
    xxxxxx 07/05/14 17:07:26
    0
    Ignition On
    xxxxxx 07/05/14 17:07:27
    0
    Start
    xxxxxx 07/05/14 17:08:05
    0.2
    Error report
    xxxxxx 07/05/14 17:09:00
    0.3
    Time Send
    xxxxxx 07/05/14 17:13:01
    0.2
    Time Send
    xxxxxx 07/05/14 17:14:01
    0.2
    Time Send
    xxxxxx 07/05/14 17:31:02
    0.4
    Time Send
    xxxxxx 07/05/14 17:32:03
    0.2
    Time Send
    xxxxxx 07/05/14 17:32:08
    0
    Acc. Summary
    xxxxxx 07/05/14 17:32:08
    0
    Stop 1.5
    xxxxxx 07/05/14 17:32:08
    0
    Bus Ignition Off
    xxxxxx 07/05/14 17:32:08
    0
    Ignition Off
    xxxxxx 08/05/14 17:00:42
    0
    Time Send

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    you could scan thru each record , counting as you go , then update the record....
    Code:
    Public Sub Milage()
    Dim rst As Recordset
    Dim dMils As Double, dDist As Double
    On Error GoTo errMakeTbl
    'query to sort data by vehicle/time
    Set rst = CurrentDb.OpenRecordset("qsCarLog")
    With rst
        While Not .EOF
           vRsn = .Fields("Reason").Value & ""
           dDist = .Fields("Distance (mi)").Value & ""
           If vRsn = "Start" Then dMils = 0
           dMils = dMils + dDist
           
           If vRsn = "End" Then
               .Edit
               .Fields("Calc Field").Value = dMils
               .Update
           End If
          .MoveNext
        Wend
    End With
    rst.Close
    Set rst = Nothing
    End Sub
    Last edited by ranman256; 05-15-2014 at 06:37 AM. Reason: spellg

  3. #3
    Martin001 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    2
    Thanks ranman256

    I thinks I can make That work

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 13
    Last Post: 03-20-2014, 09:31 AM
  2. Replies: 4
    Last Post: 11-20-2013, 03:04 PM
  3. Vehicle Mileage Database
    By Mtyetti2 in forum Access
    Replies: 6
    Last Post: 10-07-2013, 01:50 PM
  4. Vehicle Mileage
    By Mtyetti2 in forum Forms
    Replies: 5
    Last Post: 02-16-2013, 08:23 AM
  5. Replies: 12
    Last Post: 02-22-2011, 03:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums