Results 1 to 7 of 7
  1. #1
    cowboy is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2010
    Posts
    291

    quick query syntax questions

    PARAMETERS [Forms]![Main Form]![cmbArea] Text ( 255 );
    SELECT InspectionsDI.ID,InspectionsDI.Area
    FROM InspectionsDI
    WHERE InspectionsDI.Area=Forms![Main Form]!cmbArea;

    This code works correctly but I also want to allow all the records to show if Forms![Main Form]!cmbArea = "ALL"



    I am not sure how to do this, I tried If statement but my syntax must have been wrong, thanks for help.

  2. #2
    llkhoutx is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Jan 2010
    Location
    Houston, Texas USA
    Posts
    373
    To retrieve all records use (using your notation)
    Code:
    SELECT InspectionsDI.ID,InspectionsDI.Area
    FROM InspectionsDI 
    or
    Code:
    SELECT InspectionsDI.ID,InspectionsDI.Area
    FROM InspectionsDI
    WHERE InspectionsDI
    .Area Like "*" 
    or
    Code:
    If  isnull([Forms]![Main Form]![cmbArea]) = true then
    SELECT InspectionsDI
    .ID,InspectionsDI.Area
     FROM InspectionsDI
    else
    SELECT InspectionsDI.ID,InspectionsDI.Area
     FROM InspectionsDI
    end 
    if 
    Note that "InspectionsDI." prefix to field names isn't required in your simple SQL query.

  3. #3
    cowboy is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2010
    Posts
    291
    None of those options worked, any other ideas?

  4. #4
    NTC is offline VIP
    Windows Vista Access 2007
    Join Date
    Nov 2009
    Posts
    2,392
    ummmm - the first example must work because all it is doing is dropping the WHERE clause and thus all should return.....if that doesn't work then there is some sort of misunderstanding in your description....

    are you passing that sql statement via vba with an Run Query or are your using a defined query?

  5. #5
    cowboy is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2010
    Posts
    291
    Check out the original post, you didnt just drop the Where clause from the first there is a parameter sent in when the query is called. If I drop the Where clause the query becomes pointless. I just need to have another possibility.

  6. #6
    NTC is offline VIP
    Windows Vista Access 2007
    Join Date
    Nov 2009
    Posts
    2,392
    build your query using the query design grid......and then when it is working the way you want - - change it to sqlview to see the syntax....

  7. #7
    cowboy is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2010
    Posts
    291
    by query design grid do you mean design view? I dont see anywhere that lets me set conditions using design view, how would I do that?

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

Similar Threads

  1. Disable/Hide Quick Access Toolbar
    By Jackal in forum Security
    Replies: 10
    Last Post: 11-22-2012, 05:25 PM
  2. Looking for quick opinion on simple database
    By Zoran in forum Database Design
    Replies: 6
    Last Post: 01-31-2010, 05:04 PM
  3. Syntax error (comma) in query expression
    By KLynch0803 in forum Programming
    Replies: 3
    Last Post: 01-18-2010, 03:35 AM
  4. Sql Syntax Query
    By Matthieu in forum Queries
    Replies: 4
    Last Post: 12-30-2009, 09:41 AM
  5. Replies: 1
    Last Post: 10-07-2009, 07:36 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