Results 1 to 5 of 5
  1. #1
    Jeff_in_KCMO is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2014
    Posts
    3

    Conditional Query with conditional results

    I am querying table1, field1 which is a number value.

    I have a form (form1) where I am entering the max (field1Max) and min (field1Min) values for field1 to be queried.



    I need help creating a query that basically does this, which does not work: iif(forms.form1.field1Min is null AND forms.form1.field1Max is not null, table1.field1 <= forms.form1.field1Max,0)

    so basically, if the user does not input a value for field1Min, but does input a value for field1Max, the query will return all records where table1.field1 <= field1Max.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    You would need a condition on which Qry to open:

    Code:
    dim vQry
    
    select case true
       case isnull(field1Max) and isnull(field1Min)
            vQry = "qsAll"
       case isnull(field1Max) and not isnull(field1Min)
            vQry = "qsOnlyMin"
       case not isnull(field1Max) and isnull(field1Min)
            vQry = "qsOnlyMax"
       case else
            vQry = "qsBothMinMax
    end select
    
    docmd.openquery vQry

  3. #3
    Jeff_in_KCMO is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2014
    Posts
    3
    I haven't mentioned that the above is just a small part of a larger query. Keeping that in mind, how would I go about putting your suggestion into the primary query?

    And, my apologies for my ignorance, and appreciation for the help.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Are the fields text type? Can try LIKE and wildcard: http://www.datapigtechnologies.com/f...earchform.html

    I don't use dynamic parameterized queries. I prefer to apply filter to form or report: http://www.allenbrowne.com/ser-62code.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Jeff_in_KCMO is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2014
    Posts
    3
    June7, fields are a mixture of text, number, and dates.

    Unfortunately IT keeps me from opening the datapigtechnologies link.

    I will have to take a close look at the allenbrowne page. I'm working on this on my own time between actual work.

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

Similar Threads

  1. Conditional query concatenation
    By IroncladRooster in forum Access
    Replies: 6
    Last Post: 09-08-2014, 09:37 AM
  2. Replies: 6
    Last Post: 05-26-2013, 09:10 PM
  3. Conditional count in query
    By jbr87 in forum Queries
    Replies: 1
    Last Post: 09-27-2011, 12:06 PM
  4. Conditional Query
    By thegladiator in forum Queries
    Replies: 1
    Last Post: 01-14-2011, 11:44 AM
  5. Conditional Format Query
    By Schwagr in forum Queries
    Replies: 3
    Last Post: 03-20-2006, 02:39 PM

Tags for this Thread

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