query only shows some records of given criteria

L

Laurie

I'm trying to learn to do simple sql stuff, and I'm stumped. I have an
unbound form, with unbound controls, to input criteria for a query.
When I enter criteria, I only receive records that have unique entries
in the given field(s). For example, if I request a list of records for
cities that start with "S", I will get only one record for each unique
city name. Same for company name - it only shows one for each unique
company name. Clearly something is written wrong in my code. Query looks
like this:
SELECT Companies.CompanyName, Companies.ContactFirstName,
Companies.ContactLastName, Companies.City, Companies.State,
Companies.PhoneNumber, Companies.CompanyID
FROM Companies
WHERE (((Companies.CompanyName) Like
IIf(IsNull([Forms]![Search_Form]![CompanyName]),"*",[Forms]![Search_Form]![CompanyName]
& "*")) AND ((Companies.ContactFirstName) Like
IIf(IsNull([Forms]![Search_Form]![ContactFirstName]),"*",[Forms]![Search_Form]![ContactFirstName]
& "*")) AND ((Companies.ContactLastName) Like
IIf(IsNull([Forms]![Search_Form]![ContactLastName]),"*",[Forms]![Search_Form]![ContactLastName]
& "*")) AND ((Companies.City) Like
IIf(IsNull([Forms]![Search_Form]![City]),"*",[Forms]![Search_Form]![City]
& "*")) AND ((Companies.City) Like
IIf(IsNull([Forms]![Search_Form]![State]),"*",[Forms]![Search_Form]![State]
& "*")) AND ((Companies.State)

Any help, please? Thank you very much for your input.
 
V

Van T. Dinh

1. The last part of your posted Query is wrong. You compare the Filed
values for City against the Sate value on the Form but it could be just
mistake in copy & paste???

2. Try:

SELECT DISTINCTROW ...

rather than simply SELECT. You shouldn't need the DISTINCTROW, though.
 

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