Results 1 to 3 of 3
  1. #1
    joolio is offline Novice
    Windows XP Access 2002
    Join Date
    Dec 2009
    Posts
    1

    Table Values As Query Input?

    I've been looking for a solution for this problem everywhere but to no avail. I have a table with a list of values that I need to use as search criteria for a query. More specifically, this table contains two columns of values: 1) the name of the table where the query should search and 2) the column that the query should search. Let me give a simplified example:

    The table of values:
    TableName | ColumnName
    -----------------------
    Fruits | Apples
    Fruits | Bananas
    Fruits | Oranges
    Vegetables | Mushrooms
    Vegetables | Carrots


    So the list would be passed five times through the query to produce 5 different results. For instance, the query would be pointed to the 'Fruits' table to sort through the information in the 'Apples' column, as would be the case for each row.

    Let's take an example query:

    SELECT Count (*)
    FROM %TableName%


    WHERE %ColumnName% IS NOT NULL;

    Now, I know the %TableName% and %ColumnName% "variables" are not correct, but I just wanted them to serve as placeholders. What I would like to happen is have each variable replaced with a corresponding set of values from my table. So it would look like:

    SELECT Count (*)
    FROM Fruits
    WHERE Apples IS NOT NULL;

    SELECT Count (*)
    FROM Fruits
    WHERE Bananas IS NOT NULL;

    SELECT Count (*)
    FROM Fruits
    WHERE Oranges IS NOT NULL;

    SELECT Count (*)
    FROM Vegetables
    WHERE Mushrooms IS NOT NULL;

    SELECT Count (*)
    FROM Vegetables
    WHERE Carrots IS NOT NULL;

    Thus every row would be treated as a separate query, and this would be done automatically. I have NO idea how to do this, as I'm doing it manually now. Thank you for your help!

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows XP Access 2002
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    In the example you supplied I believe Apples should be a record in the Fruits table and not a field. Same with the Vegetable table. It looks to me as though you may have a normalization issue first.

  3. #3
    alcoool is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2009
    Posts
    10
    try this as a criteria
    In (select[field name]from[table name])

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

Similar Threads

  1. Replies: 0
    Last Post: 12-21-2009, 12:15 AM
  2. Creating input box for query
    By dcecil in forum Queries
    Replies: 1
    Last Post: 06-23-2009, 10:08 AM
  3. Display Query Value That Requires Input Parameter
    By Access::Student in forum Access
    Replies: 1
    Last Post: 05-29-2009, 08:43 PM
  4. Replies: 0
    Last Post: 04-26-2008, 09:59 AM
  5. How to query boolean values from table
    By kevdmiller in forum Queries
    Replies: 2
    Last Post: 11-30-2006, 07:41 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