Results 1 to 8 of 8
  1. #1
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368

    multiple optional criteria

    Hi all,



    I'm working on a reporting system that runs some analysis on the effectiveness of our campaigns. I have a table that has all of the enrollments for the year. A form will be used to create a report of some totals and percentages determining the effectiveness of a campaign. The user will be able to select a specific campaign, a zip code, the contractor the campaign was assigned to, or any combination of the three to group the enrollments by for analysis. This leads to 9 possible combinations and 9 possible queries. Currently, my plan is the create a select case and write out the SQL for each combination. This seems a bit brute force to me.

    Is there a more efficient way to attack this?

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    that's the only other way sir, unless you want a query that looks like this:

    Code:
    SELECT * FROM table WHERE
    
    ((field1 = forms!form!field1 OR forms!form!field1 IS NULL) AND 
    ((field2 = forms!form!field1 OR forms!form!field2 IS NULL) AND 
    ((field3 = forms!form!field1 OR forms!form!field3 IS NULL) AND 
    ((field4 = forms!form!field1 OR forms!form!field4 IS NULL) AND 
    ((field5 = forms!form!field1 OR forms!form!field5 IS NULL) AND 
    ((field6 = forms!form!field1 OR forms!form!field6 IS NULL) AND 
    ((field7 = forms!form!field1 OR forms!form!field7 IS NULL) AND 
    ((field8 = forms!form!field1 OR forms!form!field8 IS NULL) AND 
    ((field9 = forms!form!field1 OR forms!form!field9 IS NULL))
    that's the only way you can effectively deal with optional criteria in forms.

  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,521
    I often use Adam's technique when there's only a couple of fields, but the query design grid will often take that and make it unreadable. You might try it with your 3, which may still be manageable. When I have more than a couple, I tend to create dynamic SQL, as is done in the sample db here:

    http://www.baldyweb.com/BuildSQL.htm

    In your situation, rather than setting a recordsource I'd build a wherecondition to use with this technique:

    http://www.baldyweb.com/wherecondition.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by pbaldy View Post
    the query design grid will often take that and make it unreadable.
    AMEN. Can we participate in MS bashing now?

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Sure; I've got all kind of pet peeves with MS.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    This thread is now about your issues with Access "features"

  7. #7
    Join Date
    Jan 2011
    Posts
    13
    ajetrumpet and pbaldy have already hinted at this but:

    Generate a query in the record source of the report, select each field that belongs in the report, and set the criteria to the the Form's controls.

    The Form needs to stay open when you generate the report.

  8. #8
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by TheShabz View Post
    This thread is now about your issues with Access "features"
    Who's? MINE? what feature? the jumbled SQL feature? I believe the version of that is now at ?.?.?.?

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

Similar Threads

  1. SQL query with an optional date field
    By StevenBee in forum Programming
    Replies: 1
    Last Post: 05-30-2011, 02:40 PM
  2. Compile Error: Argument Not Optional
    By bg18461 in forum Access
    Replies: 1
    Last Post: 12-01-2010, 08:47 AM
  3. Skipping optional arguments
    By canfish in forum Programming
    Replies: 3
    Last Post: 08-19-2010, 01:35 PM
  4. Replies: 2
    Last Post: 06-23-2010, 06:37 PM
  5. Multiple criteria query
    By DJ-Specter in forum Queries
    Replies: 1
    Last Post: 09-23-2009, 04:47 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