0

I'm attempting to use the query builder to formulate a query based on user input on a form, but I'm running into an issue.

I've been using this code to filter and check for null/"ALL" field before which is working fine.

Like IIf([Forms]![TransactionsForm]![ComboActStatus]="ALL","*",
[Forms]![TransactionsForm]![ComboActStatus])

But I run into an issue when I want to do the same thing with fields that signify a range. I attempted this:

IIf([forms]![TransactionsForm]![txtAmountFrom] Is Null Or 
[forms]![TransactionsForm]![txtAmountTo] Is Null,
([dbo_customerQuery].[amount]) Like "*",
([dbo_customerQuery].[amount])>=[forms]! [TransactionsForm]![txtAmountFrom] And
([dbo_customerQuery].[amount])<=[Forms]![TransactionsForm]![txtAmountTo])

But it's causing my entire query to fail. How can I do this similar thing? Use "Like *" in the null case (return everything), but use comparators rather than "like" statements in the second case?

2 Answers 2

0

Unless I'm missing something LIKE "*" will return true for all values, so this should work:

IIf([forms]![TransactionsForm]![txtAmountFrom] Is Null Or 
    [forms]![TransactionsForm]![txtAmountTo] Is Null,
true,
([dbo_customerQuery].[amount])>=[forms]! [TransactionsForm]![txtAmountFrom] And
[dbo_customerQuery].[amount])<=[Forms]![TransactionsForm]![txtAmountTo])
)
8
  • Im doing this inside a criteria in query designer, not a where statement. So what do I put before the iif statement? Anything? Or is that how it starts? Since this still doesn't seem to be working. Commented Jul 21, 2014 at 19:15
  • Can you put in 1=1 or some other criteria that will always be true?
    – D Stanley
    Commented Jul 21, 2014 at 19:18
  • I mean wouldn't this version be saying that I only want ones that are equal to "true" or something? I know like "*" will return everything, but I don't know how to do a date range using a like clause Commented Jul 21, 2014 at 19:40
  • I'm struggling to see why you can't use true, but you could use >= '01-01-0001' or something like that to get all records.
    – D Stanley
    Commented Jul 21, 2014 at 19:52
  • ^That sounds like an interesting solution. My question is will that slow the query down to have to do that comparison multiple times? Commented Jul 21, 2014 at 20:01
0

The code that finally worked for me, and didn't have Access split it into separate lines was:

>=IIf([forms]![TransactionsForm]![txtAmountFrom] Is Null,0,[forms]![TransactionsForm]!
[txtAmountFrom]) And <=IIf([forms]![TransactionsForm]![txtAmountTo] Is Null,9999999999,
[forms]![TransactionsForm]![txtAmountTo])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.