Results 1 to 5 of 5
  1. #1
    Gina Maylone is offline Always learning
    Windows 7 64bit Access 2013
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544

    Mental gymnastics over last day of rental

    Hello! Happy Holidays from the northland!

    I have a rental database, in which I am trying to find the last location a piece of equipment was at and indicate in the inventory list whether it is in or out. But because equipment gets rented and returned often, my end date will not come up null. I first have a query that pulls the max start date:

    Code:
    SELECT DISTINCT Order.SerialNum, Max(Order.StartDate) AS MaxOfStartDate, Order.Equipment
    FROM [Order]
    GROUP BY Order.SerialNum, Order.Equipment;
    And then another query using the first one to grab additional information (Account name, patient name etc).

    Code:
    SELECT Inventory.Equipment, Inventory.SerialNum, Account.AcctName, Order.PatientName, LastStartDate.MaxOfStartDate, Order.EndDate, IIf([maxofstartdate] Is Not Null And [enddate]=Null,"out","in") AS Status
    FROM LastStartDate INNER JOIN (Account INNER JOIN ([Order] INNER JOIN Inventory ON Order.SerialNum = Inventory.SerialNum) ON Account.AcctNum = Order.AcctNum) ON LastStartDate.SerialNum = Inventory.SerialNum
    GROUP BY Inventory.Equipment, Inventory.SerialNum, Account.AcctName, Order.PatientName, LastStartDate.MaxOfStartDate, Order.EndDate, IIf([maxofstartdate] Is Not Null And [enddate]=Null,"out","in");
    What am I forgetting? (seems like more and more everyday!)

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    You say your end date will not be Null, but that's what you're testing for. You can't test for Null with =; try the IsNull() function.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Gina Maylone is offline Always learning
    Windows 7 64bit Access 2013
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    Thank you pbaldy. I have tried that as well
    Code:
    Status: IIf(not isnull([maxofstartdate] And isnull([order.enddate],"out","in")
    but I get a wrong number of arguments error.

  4. #4
    Gina Maylone is offline Always learning
    Windows 7 64bit Access 2013
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    I got it!!!! With this:
    Code:
    Status: IIf([maxofstartdate] Is Not Null And [order.enddate] Is Null,"out","in")

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    The IsNull() usage would work if you had parens correct.

    Status: IIf(not isnull([maxofstartdate]) And isnull([order.enddate]),"out","in")
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Rental Records
    By attman in forum Programming
    Replies: 1
    Last Post: 01-21-2014, 11:49 AM
  2. Manlift Rental Database Template
    By emerbrennan in forum Access
    Replies: 1
    Last Post: 08-15-2013, 08:03 AM
  3. Tools Rental DB Help
    By abusaif in forum Access
    Replies: 6
    Last Post: 07-11-2013, 07:31 AM
  4. Rental db report issue
    By InThrees in forum Reports
    Replies: 0
    Last Post: 12-03-2010, 02:47 PM
  5. Access - car rental relationships
    By ipwn in forum Access
    Replies: 0
    Last Post: 03-09-2009, 07:18 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