Results 1 to 5 of 5
  1. #1
    TKTheKid is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    35

    Creating a query to catch exceptions in tables?

    Hello everyone,



    In the attached database file, you'll see two tables of inventory data (tableWarehouseData and tableKWIData).

    What I had the query successfully(?) do was subtract the quantity amounts in each table to find ones that didn't match and then only print those records.

    However, I'm trying to test for exceptions and I'm running into problems. What I did was add a fake record into the tableWarehouseData for ARTICLE 1111111111 and QUANTITY 218051. I was hoping this would cause the query to pick this up as a "difference" as well, but it does not.

    How would I make the query catch exceptions like these when there is ARTICLE data only in tableWarehouseData or ARTICLE data only in tableKWIData?

    I hope I explained myself well enough.

    Thank you,
    Tony
    Attached Files Attached Files

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    If you want the check for exceptions to go both directions, need a data source of all possible article numbers to be found in both tables. Create that source with a UNION query of the two tables.

    SELECT ARTICLE FROM tableKWIData
    UNION SELECT ARTICLE FROM tableWarehouseData;

    Then:

    SELECT Articles.ARTICLE, tableKWIData.QUANTITY, tableWarehouseData.QUANTITY, tableKWIData.ARTICLE, tableWarehouseData.ARTICLE, [tableKWIData.Quantity]-[tableWarehouseData.Quantity] AS Difference
    FROM tableWarehouseData RIGHT JOIN (tableKWIData RIGHT JOIN Articles ON tableKWIData.ARTICLE = Articles.ARTICLE) ON tableWarehouseData.ARTICLE = Articles.ARTICLE
    WHERE ((([tableKWIData.Quantity]-[tableWarehouseData.Quantity])>0)) OR (((tableWarehouseData.ARTICLE) Is Null)) OR (((tableKWIData.ARTICLE) Is Null));
    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.

  3. #3
    TKTheKid is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    35
    Ah, okay. When I run queryDifference it now shows the two fake exception records I expected to see from each table, but why doesn't the difference appear in the Difference column? I'm guessing because it's trying to subtract from NULL, but is there any way that the difference for those exceptions records could still appear in the Difference column? I would need that to create the report at the end.

    Also, speaking of the report, when I try to access my report reportDifference, I get the following message now:

    "The specified field 'tableKWIData.QUANTITY' could refer to more than one table listed in the FROM clause of your SQL statement."

    What does that mean? 'tableKWIData.QUANTITY' only refers to one table, doesn't it?

    Tony
    Attached Files Attached Files

  4. #4
    TKTheKid is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    35
    I used the NZ function and that solved my problem of the difference not appearing for those exceptions:

    Difference: Nz([tableKWIData].[Quantity],0)-Nz([tableWarehouseData].[Quantity],0)

    --------------------------------------------------

    But I'm still having the problem with below:


    "Also, speaking of the report, when I try to access my report reportDifference, I get the following message now:

    'The specified field 'tableKWIData.QUANTITY' could refer to more than one table listed in the FROM clause of your SQL statement.'

    What does that mean? 'tableKWIData.QUANTITY' only refers to one table, doesn't it?"

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Odd that a form based on the same design as the report did not error.

    The issue is the UNION, although I don't why. I made a table from the UNION and eliminated the query and used the new Articles table in report and it works.
    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. Replies: 2
    Last Post: 11-04-2012, 02:08 PM
  2. How to catch oracle exception error
    By nvrwrkn in forum Programming
    Replies: 2
    Last Post: 10-09-2012, 06:06 AM
  3. Replies: 27
    Last Post: 08-14-2012, 09:05 AM
  4. delete query with exceptions
    By Jerseynjphillypa in forum Queries
    Replies: 3
    Last Post: 07-11-2012, 08:07 AM
  5. Creating a query using mutliple tables
    By andrewmo in forum Queries
    Replies: 1
    Last Post: 11-21-2011, 01:11 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