Results 1 to 4 of 4
  1. #1
    jeffyyy is offline Novice
    Windows 7 Access 2007
    Join Date
    Sep 2010
    Posts
    7

    Show last residence using a query

    I have 2 tables, [Residents] and [Units]. In the [Units] table, there are listing of current and previous units with the start and end dates. Also, there is a yes/no checkbox that tells whether or not the unit is active (the current unit).
    I want a query that will tell me the last unit the person was in. So I want it to pull the unit with no active checkbox with the most recent end date.

    Can anyone tell me the best way to go about this?



    Thanks for all the help!

  2. #2
    slave138's Avatar
    slave138 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    WI
    Posts
    233
    Just create your query and in the criteria for the Date field, use the DMax function:

    Code:
    DMax("dDate","tblTable","tblTable.Resident=" & Chr(34) & [Resident] & Chr(34) & " AND tblTable.Active <> -1")
    This assumes the dDate you want to find is listed in a dDate field of the table tblTable and that the resident is also listed in the same table in the Resident field. You may need to play around a little with the [Resident] section to get it to work with your actual DB.

    It will return only the inactive record with the most recent date for the selected Resident.

  3. #3
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    Dmax is the easiest way.

    but it is very inefficient. joinning with a sub query is much faster.

  4. #4
    slave138's Avatar
    slave138 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    WI
    Posts
    233
    I agree that the query would be faster (and probably easier). I tried to create a working sample but found the table descriptions to be a little confusing.

    Is there any info the Resident table is providing which is not in the Unit table?

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

Similar Threads

  1. Query to show only last entry
    By kroenc17 in forum Queries
    Replies: 20
    Last Post: 10-18-2010, 01:53 PM
  2. Show data from query in a text box
    By jeffyyy in forum Forms
    Replies: 8
    Last Post: 10-16-2010, 11:45 AM
  3. Query, show top 10
    By lostinspace in forum Queries
    Replies: 4
    Last Post: 05-10-2010, 12:18 PM
  4. Show/Hide Columns in a Query
    By SCFM in forum Access
    Replies: 1
    Last Post: 02-23-2010, 08:04 AM
  5. Show/Unshow Columns in Query
    By simmurray in forum Queries
    Replies: 0
    Last Post: 03-28-2009, 10:03 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