Query Criteria in Access

G

Guest

Hi everyone

I have set up a Query in Access. In one of the criteria fields I have
something like this which ckecks each returned record's "state" field against
a value from a textbox. This is to see if the returned record is from the
same US state as the state selected by the user. (NY, CA, GA, MD, and the
like).

Here is the criterion:

AND ((qryLocationsByType1.State) Like
[Forms]![frmMain]![subform].[Form]![txtState] )

What I really need is a way to check the returned record's "state" field
against a list of US States to see if the returned record's "state" field is
in a set of States that the user has selected through a multi-selectable
listbox.

Here is what I have... and it returns nothing. Can someone please help? Thanks

AND ((qryLocationsByType1.State) In
([Forms]![frmMain]![subform].[Form]![txtState] ))
 
O

Ofer Cohen

The problem is that Access will recognize 'CA','MD','DC' as one string
(one value) and not seperate value for CA and MD and DC.
Look at this link on "Using a Microsoft Access Listbox to pass criteria to a
query", that way you don't need to create in a combo certain combinations,
that user can select from a list box all the values he/she would like

http://www.databasedev.co.uk/query_using_listbox.html

---------
Good Luck
BS"D


Koorosh said:
Hi everyone

I have set up a Query in Access. In one of the criteria fields I have
something like this which ckecks each returned record's "state" field against
a value from a textbox. This is to see if the returned record is from the
same US state as the state selected by the user. (NY, CA, GA, MD, and the
like).

Here is the criterion:

AND ((qryLocationsByType1.State) Like
[Forms]![frmMain]![subform].[Form]![txtState] )

What I really need is a way to check the returned record's "state" field
against a list of US States to see if the returned record's "state" field is
in a set of States that the user has selected through a multi-selectable
listbox.

Here is what I have... and it returns nothing. Can someone please help? Thanks

AND ((qryLocationsByType1.State) In
([Forms]![frmMain]![subform].[Form]![txtState] ))
 

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