if i insert no value on a query, can the programme run with a default value?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anastasio86
    New Member
    • May 2010
    • 4

    if i insert no value on a query, can the programme run with a default value?

    I can't find how, on a query, the app insertes a default value when the user gives no value . for example: the app asks you to give a time period (from-to). if the user press "enter" it takes no value and shows nothing. Can, somehow, takes two default values, one for "from" and one for "to" ?
  • MMcCarthy
    Recognized Expert MVP
    • Aug 2006
    • 14387

    #2
    The only thing I can think of is to set the criteria somewhat along the following lines.

    Code:
    SELECT ...
    FROM ...
    WHERE DateField BETWEEN UserDate1 AND UserDate2
    OR DateField BETWEEN #01/01/2009# AND #31/12/2009#

    Comment

    • anastasio86
      New Member
      • May 2010
      • 4

      #3
      i had tried your solution, and i tried again now. The problem is that if the user insert a value like #1/4/2009# for date1, the app takes the #1/1/2009# because of OR. It will work only whith an If, but i still haven't found that. Maybe with If and IsNull...

      Comment

      • MMcCarthy
        Recognized Expert MVP
        • Aug 2006
        • 14387

        #4
        Originally posted by anastasio86
        i had tried your solution, and i tried again now. The problem is that if the user insert a value like #1/4/2009# for date1, the app takes the #1/1/2009# because of OR. It will work only whith an If, but i still haven't found that. Maybe with If and IsNull...
        Sorry I was tired last night when I did this ... :)

        try this

        Code:
        SELECT ...
        FROM ...
        WHERE DateField BETWEEN iif(isnull([UserDate1]),#01/01/2009#,[UserDate1]) AND iif(isnull([UserDate2],#31/12/2009#,[UserDate2])

        Comment

        • anastasio86
          New Member
          • May 2010
          • 4

          #5
          IT WORKS!!!! thanks a lot!!!!

          Comment

          Working...