Results 1 to 8 of 8
  1. #1
    ztirffritz is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2018
    Posts
    7

    Need A Running Total

    I'm trying to get a running total in a query, but I'm struggling to get it to work the way I think it should.

    I have 4 fields in the query as follows:

    1) ToolNum(ShortText)
    Values: A-J

    2) PullDate: (Date/Time)
    Values: 6/1/2013 - 12/10/18

    3) ReleaseDate: (Date/Time)
    Values: 7/1/2013-12/10/18 (most records are null in this field)



    4) RCount: Expression
    RCount: Sum(IIf(("PullDate"<DMax("ReleaseDate","qryPullLog ") Or (IsNull([ReleaseDate]=True))),1,0))

    I'm trying to get the RCount field to be a running count. Eventually, I'll want RCount to reset to 0 when ReleaseDate isn't null, and I'll want to display an alert on a form when RCount >= 20.

    Currently, RCount results in "1" or "0" so at least part of the logic is working with 'IIF', but I'm obviously missing something with 'SUM'. What I've read indicates that it should be performing a running tally in the RCount field.

    For background, the PullDate is the date when a tool is used. ReleaseDate is the date when maintenance has been performed on the tool. RCount is the number of cycles the tool has been subjected to between maintenance intervals (ie ReleaseDate). When a tool is used the intention is that an employee will scan the tool's barcode and record a 'PullDate' entry. This should increment 'RCount' by 1. When the running total >= 20 I'll have a field on a related form display an alert that maintenance is due. When maintenance is performed it should enter a record for 'ReleaseDate' and set 'RCount' back to 0.

  2. #2
    ztirffritz is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2018
    Posts
    7
    I've attached the DB. The query I'm working on is qryReleaseCount. This is obviously still very firmly in the development stage. I need find a way to count the tool cycles, generate an alert, and reset it to 0 when maintenance is performed. All the data is generally generic just for proving concepts during development.
    Attached Files Attached Files

  3. #3
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,422
    Example of desired output might help. PullDate as you have it, is a textual string and probably should be [PullDate]. Also, the IIF is missing the alternative for when the first part is not true. The OR part is, I think, ambiguous as it's basically like you're saying give me A or B. I doubt that's what your intent is. Also, AND or OR logical operators often have to be grouped to get the desired affect. Then, if there is only one ReleaseDate, you can only make one evaluation of your expression because < Null is invalid because Null cannot be compared to anything.

    I'm not sure where you'd begin given all that and not knowing what some valid results might be.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    ztirffritz is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2018
    Posts
    7
    OK, I must have been punch drunk when I wrote this. I had a <...when it should have been >. Also, the "isnull"...part shouldn't have been in there at all. That was me trying to figure out why I was getting 0s instead of 1s (see < vs > comment earlier). Now I just need to figure out why it isn't summing all the 1s.

  5. #5
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,422
    Now I just need to figure out why it isn't summing all the 1s.
    In simple terms, you are trying to SELECT a 1 or 0 depending on the result of an expression, AND sum it in the same field. Not sure you can, but you can SELECT 1 or 0 in one field and in another field, SUM that field if you don't mind getting the sum in every record. You can also turn totals on for a query in datasheet view (summation character, ribbon) but I don't believe you can access that total outside of the query datasheet view.

    I don't see why you're using DMax on another query when that query and the one you're trying to sum in both use the same table. Why not just DMax on the table in your summing query?
    EDIT - upon reviewing your prior posts (and still not being 100% certain of the meanings) can you not just DCount the date field in tblPullLog and GroupBy PartNum?

  6. #6
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,422
    double posted by accident - removed second post for now

  7. #7
    ztirffritz is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2018
    Posts
    7
    I haven't been able to get DCount to work. I'll keep trying.

  8. #8
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,422
    SELECT tblPullLog.PartNum, Count(tblPullLog.PullDate) AS CountOfPullDate,
    DCount("PullDate","tblPullLog") AS SumOfPulls FROM tblPullLog
    GROUP BY tblPullLog.PartNum, DCount("PullDate","tblPullLog");
    Something like this?

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

Similar Threads

  1. Help with running total
    By sconnors in forum Database Design
    Replies: 17
    Last Post: 07-18-2017, 10:26 AM
  2. Replies: 6
    Last Post: 09-14-2015, 06:05 PM
  3. Running total
    By edwardcga in forum Reports
    Replies: 1
    Last Post: 11-28-2013, 12:04 PM
  4. How do I create a running total
    By dniezby in forum Access
    Replies: 5
    Last Post: 04-13-2013, 11:42 AM
  5. Running total
    By lololthis in forum Queries
    Replies: 5
    Last Post: 06-21-2011, 04:14 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