Re: Test for no records returned

From: tina (nospam_at_address.com)
Date: 04/30/04


Date: Fri, 30 Apr 2004 01:29:21 GMT

try

Dim Rst As DAO.Recordset, strSQL As String
strSQL = "SELECT...."
Set Rst = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
If Rst.BOF And Rst.EOF Then
    'code that runs when recordset is empty
End If
Rst.Close
Set Rst = Nothing

or, instead

If DCount("AnyField", "QueryName") < 1 Then
    'code that runs when query has no records
End If

if your query is the SourceObject of a form, and you're wanting to check for
records on opening the form, you may be able to use RecordsetClone instead
of opening a DAO recordset. but i've never done it that way, so can't give
you specifics. if you figure it out, please post so i can learn too. :)

hth

"Brian C" <anonymous@discussions.microsoft.com> wrote in message
news:640d01c42e42$3f3195f0$a301280a@phx.gbl...
> If I run a select query that may return no records how do
> I test that there are no records?
>
> I need to do this in code, i.e.code a select statement
> followed by the test. Thanks in advance.