Results 1 to 3 of 3
  1. #1
    steffwood is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Oct 2015
    Posts
    5

    Smile Trouble using IIf with standard dates 1/1/2015 for example

    Hi,

    I have a question, I'm using the expression builder in a query to determine which code to use based on a date.

    I've had problems with the dates, no matter what I use, it applies the false condition to the list, even if I use a date such as =1/1/2015,"X","Y".
    It always selects Y. I've checked the formatting in the input file that is linked, it is set to a date format, US MM/DD/YYYY. On the parameters in the query, property sheet there is no option for Format.

    Also, how can I use a SWITCH statement? I want to be able to say:

    If date = 1/1/2015 use X
    If date is between 1/2/2015 and 1/30/2015 use Y
    If date <= 1/1/2015 use Z



    Thank you, any help would be great.

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Are you using the date delimiter? Dates need to be delimited with the hash mark (#).
    Also note that "Date" is a reserved word in Access and shouldn't be used for object names.

    Code:
    If MyDate = #10/16/2015# Then
      X = TRUE
    End If
    Code:
    Something = Switch(MyDate < #1/1/2015#, X, MyDate = #1/1/2015#, Z, MyDate > #1/1/2015# And MyDate < #1/30/2015#, Y)

  3. #3
    steffwood is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Oct 2015
    Posts
    5
    Thank very much!

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

Similar Threads

  1. Replies: 6
    Last Post: 06-26-2015, 09:18 PM
  2. Replies: 1
    Last Post: 01-05-2015, 07:05 AM
  3. Trouble with Text field: IIF() & Dates
    By the problem in forum Reports
    Replies: 7
    Last Post: 07-25-2012, 12:50 PM
  4. more trouble with text fields as dates
    By mitchmcc in forum Queries
    Replies: 3
    Last Post: 03-14-2012, 08:51 AM
  5. Having trouble with dates in my Data Base!!!!
    By BigPhil in forum Queries
    Replies: 4
    Last Post: 02-15-2006, 12:47 PM

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