TimeElapsed Greater Than 4 hours comparison

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • accessvbanewbie
    New Member
    • Mar 2008
    • 6

    TimeElapsed Greater Than 4 hours comparison

    Hi,

    Based on post in this forum,I was able to calculate time elapsed based on start and end times.

    What I am trying to do is after getting the time elapsed. If the time elapsed is greater than 4 hours an error message is generated.

    I have not been able to do this please take a look at what I have below:

    [code=vb]Dim intGrounTHour As Integer
    Dim intGrounTMinute As Integer
    Dim intResult As Integer
    Dim intTGTime As Integer
    intTGTime = 240

    intGrounTHour = Format(Me.Total .Value, "h")
    intGrounTMinute = Format(Me.Total .Value, "N")

    intResult = CInt( intGrounTHour) + CInt(intGrounTM inute )

    If intResult > intTGTime Then
    MsgBox "Please ensure that the times that you entered are correct", vbCritical, "Data Entry Error"
    Me.txtarrtime.S etFocus
    End If[/code]

    Please help
    Last edited by Stewart Ross; Mar 18 '08, 09:41 PM. Reason: Added code tags to VB code
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    Hi. You are adding hours to minutes without converting the hours to minutes first. Change your addition to
    [code=vb]intResult = 60 * intGrounTHour + intGrounTMinute[/code]
    You don't need to use CInt in the addition when the variables are already integers.

    -Stewart

    Comment

    • accessvbanewbie
      New Member
      • Mar 2008
      • 6

      #3
      Thank You For Your Response,

      I used your suggestion but for some unknown reason intResult is not taking the added values when I debug it comes up as 0. Please take a look at all the code below.


      intResult(gets value of 0) = (60 *intGrnTHour)(g ets correct time values) + intGrnTMinutege ts (correct time values)

      Dim intGrnTHour As Integer
      Dim intGrnTMinute As Integer
      Dim intResult As Integer
      Dim intTGTime As Integer
      intTGTime = 240

      intGrnTHour = Format(Me.Total .Value, "h")
      intGrnTMinute = Format(Me.Total .Value, "N")

      intResult = (60 * intGrnTHour) + intGrnTMinute

      If intResult > intTGTime Then
      MsgBox "Please ensure that the times that you entered are correct", vbCritical, "Data Entry Error"
      Me.txtarrtime.S etFocus
      End If

      Comment

      • accessvbanewbie
        New Member
        • Mar 2008
        • 6

        #4
        Its working great now thanks for all your help.

        Comment

        Working...