Results 1 to 3 of 3
  1. #1
    Polarbilly is offline Novice
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Posts
    13

    Checking data in previous record - using DLookkup

    In a form I want to read data from a previous record so I can compare it. At present, it only shows data from the current, not previous record
    I'm obviously doing something wrong - but what. I'm using ACCESS 2007

    Table: Delivery details
    ID: ID
    Field: ORDERNO
    Form: DELIVERY DETAILS1

    Formula entered in Control Source of Field "Previous Data"
    =DLookUp("[ORDERNO]","DELIVERY DETAILS","[ID]=Forms![DELIVERY DETAILS1]![ID]-1")



    Any, and all help appreciated

  2. #2
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    if this is the controlsource to a control on the form it would be

    =DLookUp("[ORDERNO]","DELIVERY DETAILS","[ID]=" & [ID]-1)

    however you cannot rely on the previous record having an ID of current record-1. To demonstrate try this little scenario

    in a table lets say the largest ID is 100
    start to enter a new record - the ID for the new record is immediately populated with 101 - all fine and dandy
    but rather than finishing the new entry you hit the escape key (say by accident) and cancel the new entry
    you 'realise your mistake' and start to re-enter the details - but this time the ID is 102 - 101 is now gone for all time.

    Autonumbers should not be used for anything other that as a unique ID to a record and should not be assigned any other meaning.

    Databases do not have the concept of first, last, next, previous without some sort of order, so to get your previous record you need to apply an order - it might be a timestamp, it might be the largest number in a column (i.e. effectively ordering by size). I don't recommend it but you could use ID field if you feel confident enough it will always increment (at that is not guaranteed) - in which case your lookup would be

    =DLookUp("[ORDERNO]","DELIVERY DETAILS","[ID]=" & DMax("[ID]","DELIVERY DETAILS","[ID]<" & [ID]))

  3. #3
    Polarbilly is offline Novice
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Posts
    13
    Thank you very much for your prompt and extremely helpful reply - back to the drawing board

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 03-05-2014, 05:37 PM
  2. Replies: 5
    Last Post: 07-19-2013, 03:42 PM
  3. Replies: 1
    Last Post: 02-16-2013, 09:25 AM
  4. Replies: 4
    Last Post: 09-09-2011, 10:00 PM
  5. Replies: 1
    Last Post: 07-25-2011, 09:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums