Results 1 to 5 of 5
  1. #1
    AccessTokyo is offline Novice
    Windows 8 Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    2

    Please help... complicated IIf Statement

    I need to track the Delivery lot number being sold value of the below query. Please help, I am newbie to MS Access.



    The first delivery of 1000 liters is tagged as Delivery lot number ”1”, the second as “2”, the third as “3”, and so on. The column Delivery lot number being sold will track which delivery lot is currently being sold so the first four rows are tagged as “1” because they have not sold up the first delivery which is 1000 liter but it is tagged as “2” in the fifth row which means the second delivery is getting started to get sold and so on.

    The logic should like:
    Delivery lot number being sold = IIf ((Delivery of Delivery lot number (n) – Sold Running Total) < 0, (Delivery lot number(n) +1), Delivery lot number (n))

    Click image for larger version. 

Name:	query2.png 
Views:	15 
Size:	12.0 KB 
ID:	23755
    Attached Thumbnails Attached Thumbnails query.png  
    Last edited by AccessTokyo; 02-19-2016 at 05:22 PM.

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    This is a bad design if this is your table structure. IF you are not in control of the structure of this table or the content of the database you might be better off doing this in a report and not attempting to do this in a query. Or alternately exporting it to excel and doing what you want with a formula, this is not a normalized structure and there are tons of issues if this is the extent of your data.

  3. #3
    AccessTokyo is offline Novice
    Windows 8 Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    2
    Hi RPeare,
    What do you mean not in control of the structure of table? the first four columns are as simple as you see it (the data or values are already there). only the fifth query column I need a logic to put 1 or 2 or 3 or 4 or so on.
    In other forums too, people just dispose of my inquiry saying design is bad blah, blah, blah, and not really able to provide concreate solution. If you suggest to put this in report, can you be specific how to?

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    In terms of receipt/disbursements of *anything* the structure you have shown is really bad for a variety of reasons.

    1. There is no way to organize the data the same way (reliably) every time so, for instance it's possible for a query to run on your data and have the last record appear first which would throw off all of your formulas
    2. You are storing a receipt and disbursement on the same record

    These are the two big ones, what you actually want is a more normalized structure like

    Code:
    tblTransactionType
    TT_ID  TT_Desc
    1      Receipt
    2      Disbursement
    
    tblTransaction
    T_ID  TT_ID  T_Qty  T_LotID  T_Date
    1     1      1000   1       1/1/2015
    2     2      20             1/1/2015
    3     2      100            1/2/2015
    4     2      850            1/3/2015
    5     1      500    2       1/3/2015
    6     2      20             1/4/2015
    7     2      30             1/5/2015
    8     1      2000   3       1/5/2015
    9     2      400            1/6/2015

  5. #5
    NTC is offline VIP
    Windows 7 64bit Access 2013
    Join Date
    Nov 2009
    Posts
    2,392
    In terms of an IIF statement - it appears you pretty much nailed it and it is just a matter of using brackets around field names, and of course using the exactly correct field name:

    Delivery lot number being sold = IIf ([Delivery lot number] – [Sold Running Total] < 0, [Delivery lot number] +1, [ Delivery lot number])

    the comma separates the clauses - so you don't really need ( ) for simple math within a clause, although it is ok....

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

Similar Threads

  1. Too complicated
    By sharonir22 in forum Queries
    Replies: 5
    Last Post: 08-11-2015, 02:46 PM
  2. Complicated Query
    By RozS in forum Access
    Replies: 5
    Last Post: 01-28-2014, 02:49 PM
  3. Complicated Validation
    By elcinolmez in forum Access
    Replies: 1
    Last Post: 09-26-2013, 01:49 AM
  4. Complicated
    By Ganymede in forum Queries
    Replies: 3
    Last Post: 01-22-2012, 06:25 PM
  5. Complicated IIF?
    By Sweetnuff38 in forum Queries
    Replies: 1
    Last Post: 08-18-2011, 01:13 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