[AccessD] adding Time

Robert Gracie Subscriptions at servicexp.com
Mon Jun 16 19:15:47 CDT 2003


Ok this is what I have right now, and it "Seems" to work, what do you guys
think?


Robert Gracie
www.servicexp.com


Private Sub cmdCalcTime_Click()
Dim SUX As Date
Dim MOX As Date
Dim TUX As Date
Dim WEX As Date
Dim THX As Date
Dim FRX As Date
Dim SAX As Date
Dim TotalMin As Variant

On Error GoTo HandleErr
SUX = Me.txtSunTotal
MOX = Me.txtMonTotal
TUX = Me.txtTueTotal
WEX = Me.txtWedTotal
THX = Me.txtThurTotal
FRX = Me.txtFriTotal
SAX = Me.txtSatTotal


TotalMin = SUX + MOX + TUX + WEX + THX + FRX + SAX

Me.txtTotalHours = FormatInterval(TotalMin, "H M")

ExitHere:
    Exit Sub

' Error handling block added by Error Handler Add-In. DO NOT EDIT this block
of code.
' Automatic error handler last updated at 06-16-2003 20:06:06
'ErrorHandler:$$D=06-16-2003    'ErrorHandler:$$T=20:06:06
HandleErr:
    Select Case Err.Number
        Case Else
            MsgBox "Error " & Err.Number & ": " & Err.Description,
vbCritical, "Form_frmTimeCardDates.cmdCalcTime_Click"
'ErrorHandler:$$N=Form_frmTimeCardDates.cmdCalcTime_Click
            'Log Error
            Call ErrorRecordSystem(Err.Number, Err.Description, Now,
"Un-Expected Error In Proc; " & "Form_frmTimeCardDates.cmdCalcTime_Click",
CurrentUser)  'ErrorHandler:$$N=Form_frmTimeCardDates.cmdCalcTime_Click

    End Select
' End Error handling block.
End Sub





Function FormatInterval(ByVal interval As Variant, Fmt As String)
'
' Formats the difference between 2 dates or sum of 2 times
' to show day as well as hours, minutes, and seconds.
'
' Supports the following formats:
'   D H                    5 Days 5 Hours
'   D H:MM                 5 Days 5:15
'   D HH:MM                5 Days 05:15
'   D H:MM:SS              5 Days 5:15:45
'   D HH:MM:SS             5 Days 05:15:45
'   H M                    125 Hours 15 Minutes
'   H:MM                   125:15
'   H:MM:SS                125:15:45
'   M S                    7515 Minutes 45 Seconds
'
Dim days As Long, hours As Long, minutes As Long, Seconds As Long
'
' Check for Date or Double
'
  If varType(interval) <> 7 And varType(interval) <> 5 Then Exit Function
'
' Parse Days
'
  days = Int(interval)
  interval = interval - days
  If interval > #11:59:59 PM# Then
    days = days + 1
    interval = 0#
  End If
'
' Parse Hours
'
  interval = interval * 24
  hours = Int(interval)
  interval = interval - hours
  If interval > 3599# / 3600# Then
    hours = hours + 1
    interval = 0#
  End If
'
' Parse Minutes
'
  interval = interval * 60
  minutes = Int(interval)
  interval = interval - minutes
  If interval > 59# / 60# Then
    minutes = minutes + 1
    interval = 0#
  End If
'
' Parse Seconds
'
  Seconds = Int(interval * 60 + 0.5)
'
' Normalize
'
  If Seconds = 60 Then
    minutes = minutes + 1
    Seconds = 0
  End If
  If minutes > 59 Then
    hours = hours + 1
    minutes = minutes - 60
  End If
  If hours > 23 Then
    days = days + 1
    hours = hours - 24
  End If
'
' Create format
'
  Select Case Fmt
    Case "D H"
      FormatInterval = days & IIf(days <> 1, " Days ", " Day ") & hours &
IIf(hours <> 1, " Hours", " Hour")
    Case "D H:MM"
      FormatInterval = days & IIf(days <> 1, " Days ", " Day ") & hours &
":" & Format(minutes, "00")
    Case "D HH:MM"
      FormatInterval = days & IIf(days <> 1, " Days ", " Day ") &
Format(hours, "00") & ":" & Format(minutes, "00")
    Case "D H:MM:SS"
      FormatInterval = days & IIf(days <> 1, " Days ", " Day ") & hours &
":" & Format(minutes, "00") & ":" & Format(Seconds, "00")
    Case "D HH:MM:SS"
      FormatInterval = days & IIf(days <> 1, " Days ", " Day ") &
Format(hours, "00") & ":" & Format(minutes, "00") & ":" & Format(Seconds,
"00")
    Case "H M"
      hours = hours + days * 24
      FormatInterval = hours & IIf(hours <> 1, " Hours ", " Hour ") &
minutes & IIf(minutes <> 1, " Minutes", " Minute")
    Case "H:MM"
      hours = hours + days * 24
      FormatInterval = hours & ":" & Format(minutes, "00")
    Case "H:MM:SS"
      hours = hours + days * 24
      FormatInterval = hours & ":" & Format(minutes, "00") & ":" &
Format(Seconds, "00")
    Case "M S"
      minutes = minutes + (hours + days * 24) * 60
      FormatInterval = minutes & IIf(minutes <> 1, " Minutes ", " Minute ")
& Seconds & IIf(Seconds <> 1, " Seconds", " Second")
    Case Else
      FormatInterval = Null
  End Select
End Function





-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com]On Behalf Of MartyConnelly
Sent: Monday, June 16, 2003 7:57 PM
To: accessd at databaseadvisors.com
Subject: Re: [AccessD] adding Time


How about some variation of this you can use datediff or dateadd functions
Sub diftest()
Dim TheDate As Date
Dim Msg As String
Dim testdate As Date
Dim testtime As Date
testdate = Date + #10:59:00 AM#
Msg = "Minutes from previous: " & Abs(DateDiff("n", Now, testdate))
MsgBox Msg
End Sub

Robert Gracie wrote:

>A2K
>
> I have 7 unbound text boxes that have time amounts listed in HH:MM (8:27)
>format.
>
>How do I go about adding up the time?  Everything I try, I get a data
>mismatch error...
>
>
>
>Thanks
>Robert Gracie
>
>
>
>
>
>
>-----Original Message-----
>From: accessd-bounces at databaseadvisors.com
>[mailto:accessd-bounces at databaseadvisors.com]On Behalf Of Charlotte
>Foust
>Sent: Monday, June 16, 2003 6:20 PM
>To: accessd at databaseadvisors.com
>Subject: RE: [AccessD] OpenArgs question
>
>
>And in the report's events, it can't see the OpenArgs string value?  Is
>the listbox value a string in the first place?  I notice you're
>delimiting it with chr(34)s, but you don't need them if it's not a date
>or numeric value.
>
>Charlotte Foust
>
>-----Original Message-----
>From: Susan Harkins [mailto:harkins at iglou.com]
>Sent: Monday, June 16, 2003 1:51 PM
>To: accessd at databaseadvisors.com
>Subject: Re: [AccessD] OpenArgs question
>
>
>OK, I'm using AXP.
>
>I'm selecting a single item from a list box and trying to pass that
>value (a
>string) to the report via the report's OpenArgs value.
>
>Susan H.
>
>
>
>
>>Susan,
>>
>>I'm getting confused.  Where are you trying to recognize it, and where
>>
>>
>
>
>
>>does a form come into the equation?  Only A2002 has an OpenArgs
>>argument for reports.  Earlier versions didn't have it.  We use it in
>>reports without problems, so what are you trying to do that isn't
>>succeeding?
>>
>>Charlotte Foust
>>
>>-----Original Message-----
>>From: Susan Harkins [mailto:harkins at iglou.com]
>>Sent: Monday, June 16, 2003 12:50 PM
>>To: AccessD at databaseadvisors.com
>>Subject: [AccessD] OpenArgs question
>>
>>
>>This should be an easy one. The following event procedure opens a
>>report and passes the list box' value as th OpenArgs setting.
>>
>>Private Sub lstCategories_DblClick(Cancel As Integer)
>>  Dim str As String
>>  str = Chr(34) & Me.lstCategories.Value & Chr(34)
>>  Debug.Print str
>>  DoCmd.OpenReport ReportName:="Catalog", _
>>      View:=acViewPreview, _
>>      OpenArgs:=str
>>End Sub
>>
>>Problem is, I can't get the report to recognize it -- in any report
>>event.
>>
>>Reports!reportname.OpenArgs
>>Me.OpenArgs
>>rpt.OpenArgs
>>
>>I've tried all three in most of the report's events after opening it
>>via the form and the setting isn't making it to the form. Any clue
>>what I'm doing wrong?
>>
>>Susan H.
>>
>>_______________________________________________
>>AccessD mailing list
>>AccessD at databaseadvisors.com
>>http://databaseadvisors.com/mailman/listinfo/accessd
>>Website: http://www.databaseadvisors.com
>>_______________________________________________
>>AccessD mailing list
>>AccessD at databaseadvisors.com
>>http://databaseadvisors.com/mailman/listinfo/accessd
>>Website: http://www.databaseadvisors.com
>>
>>
>>
>>
>
>_______________________________________________
>AccessD mailing list
>AccessD at databaseadvisors.com
>http://databaseadvisors.com/mailman/listinfo/accessd
>Website: http://www.databaseadvisors.com
>_______________________________________________
>AccessD mailing list
>AccessD at databaseadvisors.com
>http://databaseadvisors.com/mailman/listinfo/accessd
>Website: http://www.databaseadvisors.com
>
>
>
>_______________________________________________
>AccessD mailing list
>AccessD at databaseadvisors.com
>http://databaseadvisors.com/mailman/listinfo/accessd
>Website: http://www.databaseadvisors.com
>
>
>


_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com





More information about the AccessD mailing list