View Full Version : Identify if query returns records


PaddyIrishMan
02-06-2003, 04:31 AM
Hi all,
This is the process I'm following:

1. The user selects criteria from list boxes on a form then clicks a button.
2. A paramater query is built on the fly using the criteria selected.
3. A Form is then displayed using the query as it's recordsource.

Ok - I've done the above, my problem is; if the query returns no records; a blank form is displayed.
I'd like to handle this (using code) so that I know whether the query returns anything before displaying the form.

Any suggestions greatly appreciated.
Regards,
Patrick

DES
02-06-2003, 06:44 AM
Where you have the code to open the form you need to put in a check to see if anything has been returned by the query.

So I would do a Dlookup on the index field of the query. If the value of the Dlookup = null then I would pop up a message box stating there is no such match and then exit the sub.

It would look something like

Dim vTest

vTest = DLookup("[Index]","Query")
If IsNull(vText) then
Msgbox "No Matches"
Exit Sub
End If

Of course this would have to go before the line of code which is opening the form.

PaddyIrishMan
02-06-2003, 06:55 AM
Thanks Des,
That was what I was looking for.

Regards,
Patrick.

DES
02-06-2003, 06:58 AM
You should have actually done a DCount but if it work it works