Message box popup

  • Thread starter Thread starter Lana
  • Start date Start date
L

Lana

How do I go about making a popup say "No matches found" when the results of a
query found no matches?

Thank you.
 
I think you can use the DCount function.

something like this should get you pointed in right direction:


dim resultCount as integer

resultCount = DCount("*", "QueryName")

if resultCount = 0 then
msgbox .........
else
docmd.openquery "queryName"
end if
 
What do you plan on doing with that information when you get it?

It is not very efficient to count the number of records (DCOUNT) or even use
the DLOOKUP to get a single record from a query before doing something with
the query. If there are zero records, then you can avoid doing something,
but if there are records, then you end up having to run the query again to do
whatever it was you were going to do with the results of the query (report,
form, ...)

With queries that take more than a couple of seconds to run, I find that it
makes more sense just to open the report or form that you are using the query
for, and then use one of the events associated with that object to determine
whether there are any records in the queries result set or not, and take the
appropriate action.

If it is the RecordSource for a report, you can use the NoData event to
display a message and cancel opening the report.

If it is the RecordSource for a Form, then you can use code similar to the
following in the Forms Load event:

Public Sub Form_Load

Dim strMsg as string
strMsg = "No records, you are on a new record"
if me.recordsetclone.recordcount = 0 then msgbox strMsg

end sub

--
HTH
Dale

email address is invalid
Please reply to newsgroup only.
 
Back
Top