Re: form provides and/or params to query

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Sat, 26 Nov 2005 12:35:01 -0800, "cpsaltis"
<cpsaltis@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

>I've been trying to wrap my head around this one and am stuck.
>
>I have a table with WorkDate and ShiftNum fields. I have a form that prompts
>for the criteria. Query AND works fine. Now the fun part. I want to enter
>just a date get the results for all shifts (or the shift with no date for all
>dates). I entered these on seperate lines (in design view) to get the OR
>which works when I leave one field empty however when I enter both a date and
>shift I still get the OR's results included. When I enter both params I only
>want the AND.
>
>Any help would be appreciated.

The criteria need parentheses. It may be easier to see in SQL view;
the SQL WHERE clause would resemble

WHERE ([WorkDate] = [Forms]![YourForm]![txtWorkdate] OR
[Forms]![YourForm]![txtWorkdate] IS NULL)
AND
([ShiftNum] = [Forms]![YourForm]![txtShift] OR
[Forms]![YourForm]![txtShift] IS NULL)

When you go back to the design grid, Access will probably make a
hard-to-understand hash of this (putting the form references into
calculated fields and going to four OR lines) but it should still
work.

John W. Vinson[MVP]
.



Relevant Pages

  • Re: Counting records in a query
    ... Countcounts all records that meet the criteria in the WHERE clause. ... The query design grid is sort of limited how you specify ... SQL View, you can then Copy/Paste what I posted over ...
    (microsoft.public.access.queries)
  • Re: Update and Append
    ... Here in the newsgroups we use SQL for queries because we cannot post the query ... For an "Or" you just make sure the new criteria in on its ... own row in the design grid. ...
    (microsoft.public.access.queries)
  • Re: Programming Question
    ... B-Days,Day Shift, Afternoon Shift, and B-Nights changed but not if the ... Although you ought to have a few more spaces in your SQL statement, basically this is a question of operator precedence, isn't it? ... it's better to use parentheses if necessary to ensure the order of evaluation you intend. ... Dirk Goldgar, MS Access MVP ...
    (microsoft.public.access.modulesdaovba)
  • RE: How do I retrieve data based on multiple search criteria?
    ... criteria will be displayed. ... and I have performance data in one sheet for a given day by shift. ... four crews that rotate on three shifts called A, B, C, & D crews. ... search the entire range and then retrieve a row of information specific to ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Using SQL in Sub to fill box on mouseclick
    ... try the listbox. ... This is because the first " character in your SQL string will ... >> specific shift to show. ...
    (microsoft.public.access.formscoding)