Results 1 to 3 of 3
  1. #1
    ballaterach is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Feb 2014
    Posts
    9

    Parameter Union Queries


    Learned people I have a Parameter Union Query as follows:

    SELECT Seeds.[Veg or Plant Type], Seeds.Variety, Seeds.[Harvest Start 1]
    FROM Seeds
    WHERE (((Seeds.[Harvest Start 1]) Between [Enter start Date:] And [Enter End Date:]));
    UNION
    SELECT Seeds.[Veg or Plant Type], Seeds.Variety, Seeds.[Harvest Start 2]
    FROM Seeds
    WHERE (((Seeds.[Harvest Start 2]) Between [Enter start Date:] And [Enter End Date:]));
    UNION
    SELECT Seeds.[Veg or Plant Type], Seeds.Variety, Seeds.[Harvest Start 3]
    FROM Seeds
    WHERE (((Seeds.[Harvest Start 3]) Between [Enter start Date:] And [Enter End Date:]));
    UNION
    SELECT Seeds.[Veg or Plant Type], Seeds.Variety, Seeds.[Harvest Start 4]
    FROM Seeds
    WHERE (((Seeds.[Harvest Start 4]) Between [Enter start Date:] And [Enter End Date:]));

    When I run the query (and 2 other similar ones) it asks me for the start Date and End Date twice; what am I doing wrong folks?
    I would have expected it to ask me once or 4 times

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    Try this syntax --use a Parameters statement. These are defined once in Parameters, and used twice within the SQL. Bt only requested once

    Code:
    PARAMETERS EnterMin Currency, EnterMax Currency;
    SELECT tblOwl.id, tblOwl.Person, tblOwl.Previous, tblOwl.Current, tblOwl.Paid
    , [Previous]+[Current]-[Paid] AS BalanceOwing
    FROM tblOwl
    WHERE (((IIf(IsNull([Entermin]) And IsNull([Entermax])
    ,([Previous]+[Current]-[Paid]),([Previous]+[Current]-[Paid]) 
    Between [EnterMin] And [EnterMax]))<>False));

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    And most of us use forms to gather user input. It gives you more control and ability to validate input, and would certainly avoid this problem.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 7
    Last Post: 11-17-2017, 12:36 PM
  2. Replies: 5
    Last Post: 08-09-2017, 01:16 AM
  3. queries based on union queries
    By vicsaccess in forum Queries
    Replies: 3
    Last Post: 10-10-2015, 07:53 PM
  4. Replies: 5
    Last Post: 02-10-2014, 04:46 PM
  5. Replies: 13
    Last Post: 01-10-2012, 09:56 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