Results 1 to 4 of 4
  1. #1
    technet is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2012
    Posts
    2

    Iff query with date calc?


    I have 2 tables - Table 1: VendorDate (vendor name, ponum, po date, date out, date in, due date and notes). I'd like to create another field in the same table that calculates the difference between the 2.
    Is that possible on the same table? If so I haven't been able to find out how to do that.
    Table 2: VendorName (vendor name, and other stuff not relative to the 1st besides the vendor name).

    I created a query that creates a 3rd table with PO Num, Date In, Due Date, Vendor Name and in the field area I was using this:
    DaysLate: DateDiff("d",[Due Date],[Date In])

    When I run the query it creates a PO History table that has mostly what I need. If I change it to an Update Query it gives me:
    DateDiff("d",[Due Date],[Date In]) is not a valid name. Make sure it does not include invalid characters.....

    My biggest problem is I'd like it enter 0 or 1(or the actual number) if it's late or not instead of the actual numbers of days positive or negative. On my VendorName form I have the VendorDate table showing and also a graph of the average days late. If it's <=0 I'd like it to show just 0 and not go negative. If it's late then just have it average (might change it to count, still working on the requirements for that part) the number of days late.

    I tried
    DaysLate: Iff(DateDiff("d",[Due Date],[Date In])<=0),0,1)
    and it gives me an error.

    Not sure where to go from here.

    Thanks for any help!
    Rob

  2. #2
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,085
    Is it possible? yes. Is it smart? No If a field is calculated it can be calculated anywhere. queries, Forms, Reports. There is no good reason to save it in the data.

  3. #3
    technet is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2012
    Posts
    2
    ok I understand not having it updat a field in the same table but what about my issues with:
    DaysLate: Iff(DateDiff("d",[Due Date],[Date In])<=0),0,1)
    getting an error on that? Or is there a better way to compare 2 dates and have it put in a 0 or 1?

    DaysLate: iff(([date in]>[due date]),0,1)
    Would that work better and not give me errors?

    Sorry I'm sort of new to doing any programming in access.

  4. #4
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,085
    Missed it. It's IIF not IFF

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

Similar Threads

  1. Replies: 1
    Last Post: 06-04-2012, 07:17 PM
  2. calc field
    By nashr1928 in forum Forms
    Replies: 8
    Last Post: 11-09-2011, 09:21 PM
  3. query to update a date based on another date
    By tkendell in forum Access
    Replies: 3
    Last Post: 06-29-2011, 09:32 PM
  4. Calc fields
    By nashr1928 in forum Forms
    Replies: 5
    Last Post: 02-26-2011, 08:35 PM
  5. Replies: 2
    Last Post: 07-31-2009, 06:56 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