Troubles with "OR"

A

aaearhart

SELECT tbl_Projects.[ProjectName],
tbl_Projects.[ProjectNumber],
tbl_Projects.[ProjectManager],
tbl_Projects.[OnsiteLD],
tbl_Projects.[Onsite Assistant]
FROM tbl_Projects
WHERE (((tbl_Projects.[ProjectManager]) Like [Enter last name]
OR (tbl_Projects.[Onsite LD]) Like [Enter last name]
OR (tbl_Projects.[Onsite Assistant]) Like [Enter last name]));

I would like to enter the last name only once and have the query search all
three fields, but this does not seem to be happening.

any hints?

/amelia
 
O

Ofer

The sql lok fine but why do you use "like" if you look for a full string, use
the = sign, use the like when you search for a part of the string

SELECT tbl_Projects.[ProjectName],
tbl_Projects.[ProjectNumber],
tbl_Projects.[ProjectManager],
tbl_Projects.[OnsiteLD],
tbl_Projects.[Onsite Assistant]
FROM tbl_Projects
WHERE tbl_Projects.[ProjectManager] = [Enter last name]
OR tbl_Projects.[Onsite LD] = [Enter last name]
OR tbl_Projects.[Onsite Assistant] = [Enter last name]
 
V

Van T. Dinh

1. "Like" should always be used with wild-cards. Otherwise, use " = " as
Ofer advised.

2. The parentheses are not correct in the WHERE clause. For posting, it is
better to copy and paste (and add new lines for clarity) to avoid typing
mistakes.
 
A

aaearhart

Van T. Dinh said:
1. "Like" should always be used with wild-cards. Otherwise, use " = " as
Ofer advised.

Amelia says: That is why i'm using "Like" instead of " = "
2. The parentheses are not correct in the WHERE clause. For posting, it is
better to copy and paste (and add new lines for clarity) to avoid typing
mistakes.
Amelia says: I did copy and paste. Then I added new lines for clarity.

My parens are incorrect? Can you please tell me where?

WHERE (((tbl_Projects.[ProjectManager]) Like [Enter last name] OR
(tbl_Projects.[Onsite LD]) Like [Enter last name] OR (tbl_Projects.[Onsite
Assistant]) Like [Enter last name]));
 
A

aaearhart

I'm using "Like" because users may wish to use wildcards when searching for
data.

:)
 
V

Van T. Dinh

1. I can't see any wild cards in the SQL. Are you planning to include the
wild cards in the Parameter value? Most users don't know about wild cards so
it is safer to include the wild cards (in the SQL) for them.

2. OK, what you posted was correct (according to Access) but this is what I
would use (including the wild cards for example):

WHERE (tbl_Projects.[ProjectManager] Like [Enter last name] & "*")
OR (tbl_Projects.[Onsite LD] Like [Enter last name] & "*")
OR (tbl_Projects.[Onsite Assistant] Like [Enter last name] & "*");


--
HTH
Van T. Dinh
MVP (Access)


aaearhart said:
Van T. Dinh said:
1. "Like" should always be used with wild-cards. Otherwise, use " = " as
Ofer advised.

Amelia says: That is why i'm using "Like" instead of " = "
2. The parentheses are not correct in the WHERE clause. For posting, it is
better to copy and paste (and add new lines for clarity) to avoid typing
mistakes.
Amelia says: I did copy and paste. Then I added new lines for clarity.

My parens are incorrect? Can you please tell me where?

WHERE (((tbl_Projects.[ProjectManager]) Like [Enter last name] OR
(tbl_Projects.[Onsite LD]) Like [Enter last name] OR (tbl_Projects.[Onsite
Assistant]) Like [Enter last name]));
 

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