Adding 10 min to a time

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 213emi
    New Member
    • May 2010
    • 2

    #1

    Adding 10 min to a time

    This is a little more frustrating than i thought it would be.
    What i'm trying to do is just add 10 min to an already existing time.

    The scenario: Scheduling
    A student is partaking in various activities throught the day
    They can do multiple events in one day but a 10 min must be added on the end of each event to account for the 'walking' time to the next event.
    Each activity is 15 min long.
    Another student may start the activity while the first student is in the walking time so i can't just make the activity times 25 min.

    I have tried just adding the 10 min all sorts of ways but nothing works.
    Is there some special format i need to put the 10 min in so its the same as the time i'm adding it to?

    I am taking my first database class so i only have a basic understanding of access and vba. Anything will help though.
    Ty for your time
  • TheSmileyCoder
    Recognized Expert Moderator Top Contributor
    • Dec 2009
    • 2322

    #2
    You can write a function and put it in a module, or you can just use the build in dateAdd function. Either way here is code showing both:
    Code:
    Public Function fAdd10(dtInput As Date) As Date
        'Adds 10 minutes to a input dateTime
        fAdd10 = DateAdd("n", 10, dtInput) 'n=minutes
        
        'For debugging/testing, comment out when done
        Debug.Print "Input: " & dtInput
        Debug.Print "Output:" & fAdd10
        
    End Function

    Comment

    • TheSmileyCoder
      Recognized Expert Moderator Top Contributor
      • Dec 2009
      • 2322

      #3
      And welcome to Bytes.

      Comment

      • 213emi
        New Member
        • May 2010
        • 2

        #4
        Originally posted by TheSmileyOne
        You can write a function and put it in a module, or you can just use the build in dateAdd function. Either way here is code showing both:
        Code:
        Public Function fAdd10(dtInput As Date) As Date
            'Adds 10 minutes to a input dateTime
            fAdd10 = DateAdd("n", 10, dtInput) 'n=minutes
            
            'For debugging/testing, comment out when done
            Debug.Print "Input: " & dtInput
            Debug.Print "Output:" & fAdd10
            
        End Function
        Thank you sooo much for the fast response.

        It works but its on like a delay
        So whenever I change a value for the time its always one update behind.
        Here is the code for it

        Code:
        Private Sub ComboHour_Change()
        
        Me.Text10min.Value = Tenmin(TimeBox)
        Me.Text15min.Value = Fifteenmin(TimeBox)
        Me.TimeBox.Value = DLookup("[TimeQ]", "Query_Time_Reserve") 'this pulls the time from a query that is made up of 3 different combo boxes one for each hour, min, ampm
        
        End Sub
        Last edited by 213emi; May 19 '10, 10:21 AM. Reason: update

        Comment

        • TheSmileyCoder
          Recognized Expert Moderator Top Contributor
          • Dec 2009
          • 2322

          #5
          Well without knowing what data your query is pulling and from where, its a bit hard to guess at the underlying problem.

          But I will venture a guess anyway. *IF* Your query works off the same data as your form you need to realise that the record in the form is not updated, until you either actively save it, or switch away from the record. (If you have record selectors=true, you can see the small black triangle on the left hand side turning into a pencil whenever your editing, and back into a triangle when the record is saved(your out of edit mode).

          So since the record has not been updated/saved yet, the query is pulling old data.

          I hope this helps you, and if not, you will need to provide some more details on your table structure and design.

          Comment

          • Stewart Ross
            Recognized Expert Moderator Specialist
            • Feb 2008
            • 2545

            #6
            Smiley is absolutely spot-on in his response for your one-behind problem. If you want to save the record concerned automatically before you use the Dlookup in code you can use the Dirty (meaning 'has been modified') property of the form, like this if it is the current form:

            Code:
            If Me.Dirty then 
              Me.Dirty = False
            End If
            or if the record is on a different form:

            Code:
            With Forms("YourFormName")
              If .Dirty then 
                .Dirty = False
            End With
            You can place this in your sub if you want, but it must be before your Dlookup statement.

            -Stewart

            Comment

            Working...