query..

F

Fatih

Hi,
Desperately seeking answers...I've searched through the
help manual but nothing seems to help...
If want to set a query such that only one field has to be
filled in, e.g. First Name/Last Name, what is the
criteria that I need?
 
D

Dirk Goldgar

Fatih said:
Hi,
Desperately seeking answers...I've searched through the
help manual but nothing seems to help...
If want to set a query such that only one field has to be
filled in, e.g. First Name/Last Name, what is the
criteria that I need?

The SQL gets long, because you have to also check for Null values in the
controls you want to use as criteria. Here's an example that requires
at least one of the two controls to be filled in:

SELECT tblEmployees.* FROM tblEmployees
WHERE ((FirstName=[Forms]![frmLookup]![txtFirstName]
Or [Forms]![frmLookup]![txtFirstName] Is Null)
AND (LastName=[Forms]![frmLookup]![txtLastName]
Or [Forms]![frmLookup]![txtLastName] Is Null)
AND (([Forms]![frmLookup]![txtFirstName] Is Not Null)
Or ([Forms]![frmLookup]![txtLastName] Is Not Null)));

Here's an example that removes that last restriction, so that if neither
control is filled in, all records are returned:

SELECT tblEmployees.* FROM tblEmployees
WHERE ((FirstName=[Forms]![frmLookup]![txtFirstName]
Or [Forms]![frmLookup]![txtFirstName] Is Null)
AND (LastName=[Forms]![frmLookup]![txtLastName]
Or [Forms]![frmLookup]![txtLastName] Is Null));
 
F

Faith

Thanks!
Fatih
-----Original Message-----
Fatih said:
Hi,
Desperately seeking answers...I've searched through the
help manual but nothing seems to help...
If want to set a query such that only one field has to be
filled in, e.g. First Name/Last Name, what is the
criteria that I need?

The SQL gets long, because you have to also check for Null values in the
controls you want to use as criteria. Here's an example that requires
at least one of the two controls to be filled in:

SELECT tblEmployees.* FROM tblEmployees
WHERE ((FirstName=[Forms]![frmLookup]![txtFirstName]
Or [Forms]![frmLookup]![txtFirstName] Is Null)
AND (LastName=[Forms]![frmLookup]![txtLastName]
Or [Forms]![frmLookup]![txtLastName] Is Null)
AND (([Forms]![frmLookup]![txtFirstName] Is Not Null)
Or ([Forms]![frmLookup]![txtLastName] Is Not Null)));

Here's an example that removes that last restriction, so that if neither
control is filled in, all records are returned:

SELECT tblEmployees.* FROM tblEmployees
WHERE ((FirstName=[Forms]![frmLookup]![txtFirstName]
Or [Forms]![frmLookup]![txtFirstName] Is Null)
AND (LastName=[Forms]![frmLookup]![txtLastName]
Or [Forms]![frmLookup]![txtLastName] Is Null));

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


.
 

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