enter multiple criteria via text box

Y

yarra

This is probably really simple, but can anyone helps with this question?

I have a table with a field called UnitCode, in which the data is always
three letters followed by four numbers (eg ABC1234).

I want to create a query which selects records from the table based on a
value for UnitCode entered in a text box on a form, including wildcards. I
have set up the criteria field for the UnitCode field in the query design
view so that it reads
Like Forms!FormName!TextBoxName
This works if I have only one value in the text box, such as BIO2*. How can
I make it select all records where UnitCode is either BIO2* or GEN2*?

I have also tried doing this using a multi-select list box instead of a text
box, but the answers I found on this site were beyond me (my coding skills
are almost non-existent).

Thanks.
 
A

Allen Browne

You cannot type something like:
BIO2* or GEN2*
into a text box, and then expect your query to interpret the OR as an
operator.

The only way do that would be with code to parse the contents of the text
box, and build a filter/WhereCondition string.

If you really want to use a code-free solution, provide multiple text boxes
on your form where the user can type in values. In query design, under your
field, put the first text box on the Criteria line, the second one on the Or
line (below it), and so on. So your query grid will look like this:
Field UnitCode
Sorting
Show
Criteria Like [Forms].[Form1].[Text0]
Or Like [Forms].[Form1].[Text2]
Or Like [Forms].[Form1].[Text4]
 
Y

yarra

Thanks, Allen. I thought that might be the case, but it was worth asking. I
can see that the solution using mutliple text boxes would work, but
unfortunately in this application it would be messy. I'm going to have a go
at using the Query By Form technique instead, and see if that lets me do what
I want.

Yarra


Allen Browne said:
You cannot type something like:
BIO2* or GEN2*
into a text box, and then expect your query to interpret the OR as an
operator.

The only way do that would be with code to parse the contents of the text
box, and build a filter/WhereCondition string.

If you really want to use a code-free solution, provide multiple text boxes
on your form where the user can type in values. In query design, under your
field, put the first text box on the Criteria line, the second one on the Or
line (below it), and so on. So your query grid will look like this:
Field UnitCode
Sorting
Show
Criteria Like [Forms].[Form1].[Text0]
Or Like [Forms].[Form1].[Text2]
Or Like [Forms].[Form1].[Text4]

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

yarra said:
This is probably really simple, but can anyone helps with this question?

I have a table with a field called UnitCode, in which the data is always
three letters followed by four numbers (eg ABC1234).

I want to create a query which selects records from the table based on a
value for UnitCode entered in a text box on a form, including wildcards.
I
have set up the criteria field for the UnitCode field in the query design
view so that it reads
Like Forms!FormName!TextBoxName
This works if I have only one value in the text box, such as BIO2*. How
can
I make it select all records where UnitCode is either BIO2* or GEN2*?

I have also tried doing this using a multi-select list box instead of a
text
box, but the answers I found on this site were beyond me (my coding skills
are almost non-existent).

Thanks.
 
A

Allen Browne

Okay: here's a basic query-by-form example:
Search form - Handle many optional criteria
at:
http://allenbrowne.com/ser-62.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

yarra said:
Thanks, Allen. I thought that might be the case, but it was worth asking.
I
can see that the solution using mutliple text boxes would work, but
unfortunately in this application it would be messy. I'm going to have a
go
at using the Query By Form technique instead, and see if that lets me do
what
I want.

Yarra


Allen Browne said:
You cannot type something like:
BIO2* or GEN2*
into a text box, and then expect your query to interpret the OR as an
operator.

The only way do that would be with code to parse the contents of the text
box, and build a filter/WhereCondition string.

If you really want to use a code-free solution, provide multiple text
boxes
on your form where the user can type in values. In query design, under
your
field, put the first text box on the Criteria line, the second one on the
Or
line (below it), and so on. So your query grid will look like this:
Field UnitCode
Sorting
Show
Criteria Like [Forms].[Form1].[Text0]
Or Like [Forms].[Form1].[Text2]
Or Like [Forms].[Form1].[Text4]

yarra said:
This is probably really simple, but can anyone helps with this
question?

I have a table with a field called UnitCode, in which the data is
always
three letters followed by four numbers (eg ABC1234).

I want to create a query which selects records from the table based on
a
value for UnitCode entered in a text box on a form, including
wildcards.
I
have set up the criteria field for the UnitCode field in the query
design
view so that it reads
Like Forms!FormName!TextBoxName
This works if I have only one value in the text box, such as BIO2*.
How
can
I make it select all records where UnitCode is either BIO2* or GEN2*?

I have also tried doing this using a multi-select list box instead of a
text
box, but the answers I found on this site were beyond me (my coding
skills
are almost non-existent).
 

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