Results 1 to 6 of 6
  1. #1
    dbuck is offline Novice
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    8

    Quering to find a status


    I have a table where the lay out is
    Project # - Name - Role - Status - Status Date

    Two types of Status can be listed in the Status column either open or closed. Status dates are set for each entry into the table by project number. I have no trouble getting the Closed projects, however when there are two entries on two different dates one for 'open' and 'one closed' both entries will show up in a report that should only list projects that are 'open'. The query currently is picking each status up on it's own date and dropping the 'open' date onto the open report and the 'closed' date on to the closed report making it look like the project has two entries, when it should only have one. (either open or closed)

    I'm sure there is a way to get only Open projects, but it is eluding me.

  2. #2
    jzwp11 is offline VIP
    Windows 7 Access 2007
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    Welcome to the forum!

    Technically speaking, your database is not structured properly. If a project can have multiple statuses over time that describes a one(project)-to-many(statuses) relationship, which requires a separate but related table. Something along these lines would be more appropriate:


    tblProjects
    -pkProjectID primary key, autonumber
    -txtProjectNo
    other project fields

    tblProjectStatus
    -pkProjStatusID primary key, autonumber
    -fkProjectID foreign key relating back to tblProjects
    -statusDate
    -status

    In terms of your report you will need some queries. If a project can have multiple statuses, you need to find the most current status or in other words, for each project, you need to find the record in tblProjectStatus that has the most recent date in the statusDate field. To do this you need an aggregate query. This is what the query would look like in SQL view (SQL view is easier to show in a post compared to design view)

    SELECT fkProjectID, Max(statusDate)
    FROM tblProjectStatus
    GROUP BY fkProjectID

    You would then join this query back to the tblProjectStatus (using another query) via the fkProjectID field. This will allow you to bring in the status field.

    Although you can use the same idea as I describe above with your current table structure, I would strongly recommend that you make the change to your table structure. Having the correct table structure is critical to a successful relational database, and it will save you a lot of headaches in the long run.


    Just a couple general recommendations, the word "name" is a reserved word in Access, so it should not be used as a table or field name, so I suggest you change it to something else. Also, it is generally recommended to not have spaces or special characters (!,#, $,& etc.) in your table or field names. As a matter of fact, the # sign is a date delimiter in Access.

  3. #3
    dbuck is offline Novice
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    8

    Quering to Find Status - Follow up

    Thank you! Still working the query suggestion but have not managed to return the dataset I would have expected.

    Question regarding table structures. I 'inherited' this particular db and its to put it nicely faults. The two main tables were never assigned primary keys. Aside from using a simple record ID number as the key any other recommendations short of rebuilding each table?

  4. #4
    jzwp11 is offline VIP
    Windows 7 Access 2007
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    You still might be able to accomplish what you are after with your current structure.

    First the query to get the most recent status date for each project

    query name: qryMostRecent
    SELECT [Project #], Max([Status Date]) as MostRecentStatusDate
    FROM yourtable
    GROUP BY [Project #]

    Now join the above query back to your project table; join by both project number and status date

    query name: qryCurrentStatusOfAllProjects
    SELECT yourtable.[Project #], yourtable.[Name], yourtable.Role, yourtable.Status, yourtable.[Status Date]
    FROM yourtable INNER JOIN qryMostRecent ON yourtable.[Project #]=qryMostRecent.[Project #] AND yourtable.[Status Date]=qryMostRecent.MostRecentStatusDate

    You can now use the above query to create 2 queries, one for open projects and one for closed projects

    SELECT *
    FROM qryCurrentStatusOfAllProjects
    WHERE qryCurrentStatusOfAllProjects.Status="open"


    SELECT *
    FROM qryCurrentStatusOfAllProjects
    WHERE qryCurrentStatusOfAllProjects.Status="closed"


    Alternatively, you can make 1 query that references a control on an unbound form. The user would type either the word opened or closed in the control and then run the query below (via a command button)

    SELECT *
    FROM qryCurrentStatusOfAllProjects
    WHERE qryCurrentStatusOfAllProjects.Status=forms!formnam e!controlname

  5. #5
    dbuck is offline Novice
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    8

    Smile Quering to Find a status

    The problem was solved with last post. Thank you! Now if you could get the my users to input their data correctly! Thank you again.

  6. #6
    jzwp11 is offline VIP
    Windows 7 Access 2007
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    Now if you could get the my users to input their data correctly!
    I have the same problem! I try to use combo and list boxes whenever possible to present the user with preset choices that way I control some things--at least.

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

Similar Threads

  1. Looping through a tbl to find a certain value
    By cwf in forum Programming
    Replies: 1
    Last Post: 05-17-2010, 04:02 PM
  2. Need help to find a function
    By lil in forum Access
    Replies: 7
    Last Post: 03-24-2010, 12:14 PM
  3. Find tables
    By Jaime in forum Access
    Replies: 2
    Last Post: 11-04-2009, 01:52 PM
  4. Replies: 0
    Last Post: 09-25-2008, 12:19 PM
  5. How to Find a Record
    By lschlitt in forum Programming
    Replies: 2
    Last Post: 09-09-2006, 06:24 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