Results 1 to 3 of 3
  1. #1
    LVB is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2022
    Posts
    4

    How do I subtract consecutive records from within the same field

    Hi,
    This should be easy but....
    I have a livestock register. For each animal in the database there is parent form which contains the basic detail and there is a sub form that stores the weight of the particular animal each time its weighed. What I'm trying to do is simply calculate the change in weight from one reading to the next and display that figure in a separate column on the sub form. I dont want to store the figure, I just want to calculate and display it on the fly. I'm just not sure how to go about referencing the weight value in the preceding row so I can do the calculation.

    For example, in the sub form below I would like the "Weight gain" column to be populated with:
    first record: 270.2, which is 270.2 - 0 rcd 1 - 0
    second: 150.8, which is 421 - 270.2 rcd 2 - rcd 1
    third: 14.5, which is 435.5 - 421 rcd 3 - rcd 2

    I understand the first row would be anomaly that I would need to code around (Ie there is no preceding record) but I'm sure I can work around this once I have the method for doing rows 2 onwards.

    Thanks in advance.


  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    In databases there is no order so no previous or next - unless you specify an order. Might be a primary key, a date or something else. You are not showing anything appropriate in your example but to achieve what you want you will need to

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

Similar Threads

  1. Replies: 8
    Last Post: 01-29-2023, 04:30 PM
  2. Replies: 4
    Last Post: 04-04-2017, 08:06 AM
  3. Replies: 6
    Last Post: 05-18-2013, 01:38 PM
  4. Replies: 2
    Last Post: 01-23-2013, 11:07 AM
  5. Replies: 4
    Last Post: 10-18-2011, 03:46 PM

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