Get data from previous entry

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jgrondin
    New Member
    • May 2012
    • 2

    Get data from previous entry

    So far, when I scan a product, it records the current time with a Now function. What I need is to know how much time elapsed since my last scan by doing a Datediff function with the previous time recorded. My problem is that I can't manage to get the previous scan time.

    I thought of two ways to do this.

    1. Previous_scan = DMax("[Hours]", "Data", "Hours < Now()")
    This does not work. If I change the criteria to "Hours <= Now()", it gives me the current time as if my function could not find other times recorded than the current time.

    2. My second idea was to use a Dlookup and use my autonumber to look for "the current autonumber - 1" in order to get the previous time recorded. But I can't manage to create the variable in order to do this.


    Anyone has any idea to solve this ? I've been working on this for 2 days already and it's getting on my nerves.

    Thank you so much !
  • jgrondin
    New Member
    • May 2012
    • 2

    #2
    Here is a part of my actual code.


    "Product" is the product number when an item is scanned.
    "Hours" is the current time when an item is scanned.
    I want "Hours_fini sh" to be the time of the previous scan.

    If Product <> 0 Then
    Hours = Now()
    End If

    If Product <> 0 Then
    Previous_scan = DMax("[Hours]", "Data", "Hours < Now()")
    End If

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      Use the first method. But you need to limit on some sort of product id. What you have there returns the max of all the products. I assume you only want the max of the product you're scanning.

      Comment

      Working...