Results 1 to 6 of 6
  1. #1
    Latour is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    May 2017
    Posts
    3

    Querry citeria help

    I want to filter my query by date based on two different dates selected on a form.


    However I only want to filter by date if combo box 1 has certain text in it. I have tried the criteria below in my query however it returns a query with no results. What am I missing or doing wrong?

    IIf([Forms]![Form1]![Combo1]="Text1",([Table1].[Field1]) Between DateValue(Nz([Forms]![Form1]![Field2onform1],"1/1/1000")) And DateValue(Nz([Forms]![Form1]![Field2onform1],"*")))))

    If I ignore the value in combo box 1 with the following criteria the formula works perfectly.

    ([Table1].[Field1]) Between DateValue(Nz([Forms]![Form1]![Field2onform1],"1/1/1000")) And DateValue(Nz([Forms]![Form1]![Field2onform1]

    Please help with my IIF statement.....

    Thanks

  2. #2
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    You are referring to the first column in the combobox. Make sure that it holds the value "Text1" and not a hidden field such as ID. The first column is the first field in the row source of the combobox.

  3. #3
    Latour is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    May 2017
    Posts
    3
    Thanks for the reply. I have checked this and I don't believe it to be the problem. I will give it another look.
    Thanks

  4. #4
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    You may have too many closing brackets.

  5. #5
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    What comes between the first comma and the second
    IIf([Forms]![Form1]![Combo1]="Text1",

    is the first value to be returned if the 1st expression is True. The next part is the value to be returned if it was False. You're trying to use a criteria expression (the part containing the AND operator) which does not return a value as the first value, and nothing for the second value. At the end, the result of the Nz function is supposed to be the second part of the BETWEEN expression, but if it's Null, it returns an asterisk. Then you'd be trying to get the DateValue of (*). You'd still have no alternate value for the IIF expression.

    Not sure what all the fields represent - it all looks weird. You want to check between 2 dates from the same control? And if it is null, between 01/01/1000 and the DateValue of *? Maybe I'm not reading it right; it's been a long day.

    Why not put the text control reference in one field, and the BETWEEN expression that works in the date field on the same criteria row? Still don't see how you can reference the same control for Between 2 dates:
    Between DateValue(Nz([Forms]![Form1]![Field2onform1],"1/1/1000")) And DateValue(Nz([Forms]![Form1]![Field2onform1]
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    Latour is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    May 2017
    Posts
    3
    Micron,
    You are right there is an error in the between statement. It should read.
    Between DateValue(Nz([Forms]![Form1]![Field2onform1],"1/1/1000")) And DateValue(Nz([Forms]![Form1]![Field3onform1]

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

Similar Threads

  1. Replies: 5
    Last Post: 01-12-2016, 01:57 PM
  2. Replies: 1
    Last Post: 08-11-2015, 11:33 AM
  3. Replies: 15
    Last Post: 03-02-2014, 05:15 PM
  4. Search querry
    By sdc1234 in forum Queries
    Replies: 14
    Last Post: 06-22-2013, 08:21 AM
  5. Querry formating
    By Zoroxeus in forum Queries
    Replies: 0
    Last Post: 03-07-2006, 11:00 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