Results 1 to 4 of 4
  1. #1
    adammitchell23 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2013
    Posts
    3

    Query from list box displaying incorrect values.

    I'm trying to sort a population of animals from the table [ALL WEIGHTS] by those that are alive (from the table MainDeaths, field [STATUS: DEAD OR ALIVE], which is a list box with the options either "DEAD" or "ALIVE"). I then want to display them by last date they were weighed ([ALL WEIGHTS].[DATE OF WEIGHT]). I am doing this so I can set up a warning that tells me if a (live) animal has not been weighed in the last 14 days. I have tried this using Unique Values and Unique Records, and I've also tried making a separate "Live Animals" query and using this instead of coming straight from the MainDeaths table. I either get one of four results; 1. I get about 62000 results (there are only about 300 animals in the population). 2. I get each animal displayed twice, displayed as both "dead" and "alive". 3. I get the result that every animal in the population is "alive", which is not true. 4. The date of last weight is displayed as 26/11/2013 for every animal (this is the last time the last animal was weighed). This is the SQL I'm using - this particular code gives me the correct number of animals and the correct dates for when each animal was last weighed, but incorrectly tells me that every animal is "alive".




    Code:
    SELECT DISTINCT Last([ALL WEIGHTS].[DATE OF WEIGHT]) AS LastDate, [ALL WEIGHTS].[ANIMAL ID], MainDeaths.[STATUS: DEAD OR ALIVE]
    FROM [ALL WEIGHTS], MainDeaths
    GROUP BY [ALL WEIGHTS].[ANIMAL ID], MainDeaths.[STATUS: DEAD OR ALIVE]
    HAVING (((MainDeaths.[STATUS: DEAD OR ALIVE])="ALIVE"));
    .

    Thanks all!

    Adam

  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,641
    Certainly one problem is not having a join between the two tables. Are they related to each other?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    adammitchell23 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2013
    Posts
    3
    Hi Paul,
    Yes they are; by a field called "Animal ID" in my primary table (called MainID) - I'd upload my database, but I'm at a research station in the Kalahari and the internet is both crap and expensive!

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,627
    If you can't upload a bare bones version of db, some info on the data structure would be helpful.

    Since you are tracking individuals, presume you have a table with a unique record for each individual? You have a separate table for death info? Then you have a table for weight data and each individual can have many records?

    You want this query to show the last weigh date but don't need the weight?

    SELECT [DATE OF WEIGHT]) AS LastDate, [ANIMAL ID] FROM [ALL WEIGHTS] GROUP BY [ANIMAL ID];

    Now join that query to the MainDeath table OR the query and MainDeath to the Individuals table by linking on the [ANIMAL ID] fields.


    BTW, for future design reference, advise no spaces or special characters/punctuation (underscore is exception) in names. Also, avoid all caps. Better would be AnimalID or Animal_ID.
    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. Displaying multiple text values in crosstab query
    By MFlood7356 in forum Queries
    Replies: 6
    Last Post: 06-28-2011, 11:30 AM
  2. Incorrect Values Populating My Combo Boxes
    By charlyzaingel in forum Forms
    Replies: 19
    Last Post: 06-23-2011, 10:17 AM
  3. Replies: 9
    Last Post: 12-13-2010, 09:25 PM
  4. Replies: 3
    Last Post: 11-26-2010, 12:38 PM
  5. Replies: 3
    Last Post: 03-25-2010, 12:31 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