Criteria for "All" in a query

G

Guest

I know that the wildcard Like "*" returns all value. But I am having trouble
referencing it in the criteria of a query. I have a form with listboxes. When
the user selects a value in a listbox it places the value in a field on the
form. If the user does not make a selection in that a particular listbox the
vale defaults to the string "All". I then have the following in the criteria
of the query.

IIf([Forms]![fMainReporting]![selectDept]="All",Like
"*",[Forms]![fMainReporting]![selectDept])

I have written the syntax for the wildcard everyway I can think of; nothing
works. If there is a Dept value in [selectDept] the queries display data
fine; if the value in [selectDept] is "All" nothing is returned. It should
return all records.

Any help would be greatly appreciate.
 
F

fredg

I know that the wildcard Like "*" returns all value. But I am having trouble
referencing it in the criteria of a query. I have a form with listboxes. When
the user selects a value in a listbox it places the value in a field on the
form. If the user does not make a selection in that a particular listbox the
vale defaults to the string "All". I then have the following in the criteria
of the query.

IIf([Forms]![fMainReporting]![selectDept]="All",Like
"*",[Forms]![fMainReporting]![selectDept])

I have written the syntax for the wildcard everyway I can think of; nothing
works. If there is a Dept value in [selectDept] the queries display data
fine; if the value in [selectDept] is "All" nothing is returned. It should
return all records.

Any help would be greatly appreciate.

The Like word must come first.
Like IIf([Forms]![fMainReporting]![selectDept]="All","*",
[Forms]![fMainReporting]![selectDept])
 
G

Guest

Try this

Like IIf([Forms]![fMainReporting]![selectDept]="All",
"*",[Forms]![fMainReporting]![selectDept])
 
G

Guest

This code worked perfect! I do not understand putting the "Like" in front,
but it sure works so I am just going to accept it. Thanks a million! -Charles

fredg said:
I know that the wildcard Like "*" returns all value. But I am having trouble
referencing it in the criteria of a query. I have a form with listboxes. When
the user selects a value in a listbox it places the value in a field on the
form. If the user does not make a selection in that a particular listbox the
vale defaults to the string "All". I then have the following in the criteria
of the query.

IIf([Forms]![fMainReporting]![selectDept]="All",Like
"*",[Forms]![fMainReporting]![selectDept])

I have written the syntax for the wildcard everyway I can think of; nothing
works. If there is a Dept value in [selectDept] the queries display data
fine; if the value in [selectDept] is "All" nothing is returned. It should
return all records.

Any help would be greatly appreciate.

The Like word must come first.
Like IIf([Forms]![fMainReporting]![selectDept]="All","*",
[Forms]![fMainReporting]![selectDept])
 
K

klkropf

This works great, but what if you want it to return blank fields also?

cbjames said:
This code worked perfect! I do not understand putting the "Like" in front,
but it sure works so I am just going to accept it. Thanks a million! -Charles

fredg said:
I know that the wildcard Like "*" returns all value. But I am having trouble
referencing it in the criteria of a query. I have a form with listboxes. When
the user selects a value in a listbox it places the value in a field on the
form. If the user does not make a selection in that a particular listbox the
vale defaults to the string "All". I then have the following in the criteria
of the query.

IIf([Forms]![fMainReporting]![selectDept]="All",Like
"*",[Forms]![fMainReporting]![selectDept])

I have written the syntax for the wildcard everyway I can think of; nothing
works. If there is a Dept value in [selectDept] the queries display data
fine; if the value in [selectDept] is "All" nothing is returned. It should
return all records.

Any help would be greatly appreciate.

The Like word must come first.
Like IIf([Forms]![fMainReporting]![selectDept]="All","*",
[Forms]![fMainReporting]![selectDept])
 
D

Douglas J. Steele

Rather than

Like
IIf([Forms]![fMainReporting]![selectDept]="All","*",[Forms]![fMainReporting]![selectDept])

use

= [Forms]![fMainReporting]![selectDept] Or
([Forms]![fMainReporting]![selectDept] = "All")



--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


klkropf said:
This works great, but what if you want it to return blank fields also?

cbjames said:
This code worked perfect! I do not understand putting the "Like" in
front,
but it sure works so I am just going to accept it. Thanks a
million! -Charles

fredg said:
On Mon, 16 Jan 2006 08:31:06 -0800, cbjames wrote:

I know that the wildcard Like "*" returns all value. But I am having
trouble
referencing it in the criteria of a query. I have a form with
listboxes. When
the user selects a value in a listbox it places the value in a field
on the
form. If the user does not make a selection in that a particular
listbox the
vale defaults to the string "All". I then have the following in the
criteria
of the query.

IIf([Forms]![fMainReporting]![selectDept]="All",Like
"*",[Forms]![fMainReporting]![selectDept])

I have written the syntax for the wildcard everyway I can think of;
nothing
works. If there is a Dept value in [selectDept] the queries display
data
fine; if the value in [selectDept] is "All" nothing is returned. It
should
return all records.

Any help would be greatly appreciate.

The Like word must come first.
Like IIf([Forms]![fMainReporting]![selectDept]="All","*",
[Forms]![fMainReporting]![selectDept])
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top