none
Access 2007 VB Code

    Question

  • I am trying to implement the following code, the function part was created by another and basically allows me to subrtract the times and dates seperatly from each other...  It will work and function correctly using the double click on the form but actually doesn't update or show up until I click on another area of the form.  I wasn't sure where I needed to place the Function part of the code that was written by another.  Can someone point me in the correct direction ?

    Private Sub Combo125_DblClick(Cancel As Integer)

    Dim Hours As String
    Dim Minutes As String
    Hours = TimeDiff("h", [Start Time Trail Laid], [start time trailing])
    Dim Calculation As String
    Minutes = TimeDiff("n", [Start Time Trail Laid], [start time trailing])
    Calculation = Minutes - (60 * Hours)
    [Age of Trail] = DateDiff("d", [Date Trail Laid], [Start Date of Trailing]) & " days " & Hours & " hrs " & Calculation & " min"
    DoCmd.RunCommand acCmdSaveRecord

    End Sub

    Public Function TimeDiff(strInterval As String, _
                              dtStartTime As Date, _
                              dtStopTime As Date) As Long
                             

       TimeDiff = DateDiff(strInterval, #12:00:00 AM#, _
                     Format(TimeValue(dtStartTime) - 1 - TimeValue(dtStopTime), _
                     "hh:nn:ss"))
     
    End Function

    Tuesday, August 17, 2010 11:29 PM

Answers

  • Assuming you have a textbox on the form to show 'Age of Trail', you can add a line of code like this:

    Private Sub Combo125_DblClick(Cancel As Integer)

    Dim Hours As String
    Dim Minutes As String
    Hours = TimeDiff("h", [Start Time Trail Laid], [start time trailing])
    Dim Calculation As String
    Minutes = TimeDiff("n", [Start Time Trail Laid], [start time trailing])
    Calculation = Minutes - (60 * Hours)
    [Age of Trail] = DateDiff("d", [Date Trail Laid], [Start Date of Trailing]) & " days " & Hours & " hrs " & Calculation & " min"
    DoCmd.RunCommand acCmdSaveRecord

    Me.[NameOfAge of trail textbox] = me![Age of Trail]

    End Sub


    Jeanette Cunningham (Access MVP) Pakenham, Victoria Australia
    • Marked as answer by sailinxtc Wednesday, August 18, 2010 5:05 PM
    Wednesday, August 18, 2010 12:07 AM

All replies

  • Assuming you have a textbox on the form to show 'Age of Trail', you can add a line of code like this:

    Private Sub Combo125_DblClick(Cancel As Integer)

    Dim Hours As String
    Dim Minutes As String
    Hours = TimeDiff("h", [Start Time Trail Laid], [start time trailing])
    Dim Calculation As String
    Minutes = TimeDiff("n", [Start Time Trail Laid], [start time trailing])
    Calculation = Minutes - (60 * Hours)
    [Age of Trail] = DateDiff("d", [Date Trail Laid], [Start Date of Trailing]) & " days " & Hours & " hrs " & Calculation & " min"
    DoCmd.RunCommand acCmdSaveRecord

    Me.[NameOfAge of trail textbox] = me![Age of Trail]

    End Sub


    Jeanette Cunningham (Access MVP) Pakenham, Victoria Australia
    • Marked as answer by sailinxtc Wednesday, August 18, 2010 5:05 PM
    Wednesday, August 18, 2010 12:07 AM
  • Thank you that is what is was looking for.
    Wednesday, August 18, 2010 5:05 PM