Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Nz operator/IIF Question - Ms Access 97

Status
Not open for further replies.

salisha

IS-IT--Management
Feb 24, 2003
28
US
I am creating this Parameter query and I need a little help. I have a couple fields such as lastname, firstname, address etc. In the query design mode, I am setting the criteria where the user will be prompted for a first
name and last name and get that particular name.
For the lastname field, I set it up so the user can type the first few letters of the last name, and get all entries that pertain to it. (I used the LIKE function) So for example, the user will type in SM, and get all
lastnames that start with SM. My problem is I need help setting up the criteria for the firstname field. The user doesn't necesssarily have to type in a firstname. So I need to write some sort of criteria that if the user does not type in firstname, it will only bring up all entries with that particular last name.
So far I have this code which doesn't work if the user does not type in a first name:

IIf(Nz([Enter First Name]=""),Like [Enter first few letters of last name:] & "*",[Enter first Name])

Like [Enter first few letters of last name:] & "*", - This is the criteria i have listed under the lastname field.

PLEASE HELP!!!!!!!!!!!!!!
thanks in advance.
salisha
 
SELECT tblNames.FirstName, tblNames.LastName
FROM tblNames
WHERE (((tblNames.FirstName)=[enter first name]) AND ((tblNames.LastName) Like [enter first few letters of last name] & "*")) OR (([enter first name] Is Null) AND ((tblNames.LastName) Like [enter first few letters of last name] & "*"));

If you put this in the design grid, you will get what you want I think. Let me know how it works.

Nick
 
Hey Nick,
You are a Lifesaver!!!!!!!!!!! Thank you so much... It worked like a charm. Thank you, thank you,thank you!
salisha
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top