Results 1 to 11 of 11
  1. #1
    MGordinho is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2017
    Posts
    5

    Create 2 additional fields to a table using a query


    Hello!

    I have 2 tables:


    Table A has the allocation history of some events
    Table B has events not finished


    I need to create a new table that has all the events in table B and 2 new fields:


    1. Field 1: Checks if the event is already in table A
    2. Field 2: Checks if the event status has changed


    I have no idea how it is done. Can somebody help me?


    Thanks

  2. #2
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    You can use a Make Table Query to create your new table.

    I don't think you need Field 1 in your query at all. The General Rule of Thumb is that you should NEVER store anything which can be easily calculated "on-the-fly" at any time. You can use a simple query to see which records in your new table also have records in table A.

    Regarding your second field, you really have not mentioned anything above it about a Status field, and how you determine if an event has changed. If it is a matter of looking at other records in other tables, it will probably fall into the same situation as above. In which case, you may not need a new table at all, but rather just some simple queries between the two tables that you already have.

  3. #3
    MGordinho is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2017
    Posts
    5
    I'll try to explain exactly what I want to do.


    As I said I have 2 tables:


    A: History of events allocated
    B: List of events not finished


    Table A has several columns: Event ID | Status | Error Description | Employee | Allocation Date | Solved? | Solved Date


    Table B has the following columns: Event ID | Status | Error Description


    I want to check if the events in table B hava already been allocated to someone. The criteria must be:
    - if the event is not in table A, or
    - if the event is in table A but the status has changed


    If these conditions are not met, I need to allocate those events. How do I get a list of those events?

  4. #4
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Can you post some a small data example, showing your different situations, and what you would like to see returned?

  5. #5
    MGordinho is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2017
    Posts
    5
    I hope this helps...

    Click image for larger version. 

Name:	tableA.PNG 
Views:	12 
Size:	9.8 KB 
ID:	27880
    Click image for larger version. 

Name:	tableb.PNG 
Views:	12 
Size:	3.4 KB 
ID:	27881
    Click image for larger version. 

Name:	result.PNG 
Views:	12 
Size:	2.6 KB 
ID:	27882

  6. #6
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    It looks to me that you just want an Unmatched Query between Table B and Table A, joining on both the Event ID and Status fields (basically, it looks like you want all records from Table B where the Event ID/Status field combination is not found in Table A).

    The SQL code for that query would look like:
    Code:
    SELECT [Table B].[Event ID], [Table B].Status, [Table B].[Error Description]
    FROM [Table B] LEFT JOIN [Table A] ON ([Table B].Status = [Table A].Status) AND ([Table B].[Event ID] = [Table A].[Event ID])
    WHERE ((([Table A].[Event ID]) Is Null));

  7. #7
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    may want to throw in a solved date being null as well since it looks like he wants to exclude solved items.

  8. #8
    MGordinho is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2017
    Posts
    5
    It works just as I wanted. Thank you.


    However, I need one more criteria in my query. An event can have a status, evolve to another and get back to the previous one. In theses cases, I will need to allocate them again.
    Is it possible to check what was the last status on Table A? And if the last status in Table A is different from the one in Table B, the event should be in the query result, in order to have the complete list of events that have to be allocated.
    The events in Table A are sorted by date (oldest to newest).

  9. #9
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Is it possible to check what was the last status on Table A?
    Take a look at creating an Aggregate (Totals) Query to return the Maximum value in your date field for each Grouping.

    See:
    https://www.techonthenet.com/access/..._query2007.php
    and
    https://access-programmers.co.uk/for...d.php?t=159665

    (the second example shows you how to add levels for Grouping and not just return one single date, but a date for each group.

  10. #10
    MGordinho is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2017
    Posts
    5
    Thanks! Just what I needed

  11. #11
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    You are welcome!

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

Similar Threads

  1. create query from both fields in table
    By willfrank in forum Access
    Replies: 2
    Last Post: 04-14-2016, 12:57 PM
  2. Query to create additional field in table
    By leungyen in forum Queries
    Replies: 5
    Last Post: 05-21-2015, 11:25 AM
  3. Do I need to create additional tables?
    By jamestford in forum Queries
    Replies: 3
    Last Post: 06-06-2014, 12:34 AM
  4. Replies: 7
    Last Post: 06-19-2013, 01:25 PM
  5. Adding additional fields in form
    By ThebigCt in forum Forms
    Replies: 2
    Last Post: 02-23-2012, 12:33 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