syntax help for select statement

  • Thread starter Thread starter Deb Smith
  • Start date Start date
D

Deb Smith

I want my statement to produce all records, only those records with LastName
equal to what is identified in txtLastNameFilter AND if no records are
found to show all records.In other words, both Null and All equal show all
records

This is the statement I am currently using. It is not recognizaing is no
records are found, then show all records.

Me.RecordSource = "Select * FROM Person WHERE LastName Like """ &
txtLastNameFilter & "*"" ORDER BY Person.LastName, Person. FirstName

As you can probably tell, my knowledge is quite limited, but I believe the
above statement is inaccurate and requires something that says Null = "*". I
do not know how to do this. Can someone please help me on this.

If however, my statement does in fact cover all my parameters, if someone
could let me know, I would appreciate it. At least I would then know if
there are other issues I need to address.

Thanks so much for any help and suggestions.
 
It's not possible to have a query do what you seem to be asking for. A query
does one thing only. You're going to need to run a second query if your
first one doesn't return any rows.
 
(untested)

SELECT *
FROM Person
WHERE LastName = "Smith"
OR NOT EXISTS
( SELECT 1
FROM Person AS p2
WHERE p2.LastName = "Smith" )

Replace: = "Smith" with whatever you want.

HTH,
TC
 
Back
Top