Re: Test for no records returned
From: tina (nospam_at_address.com)
Date: 04/30/04
- Next message: Van T. Dinh: "Re: Help with code to run query and test a field in the record"
- Previous message: PC Data***: "Re: I'm struggling with my limited knowledge of code"
- In reply to: Brian C: "Test for no records returned"
- Next in thread: Cheryl Fischer: "Re: Test for no records returned"
- Messages sorted by: [ date ] [ thread ]
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.
- Next message: Van T. Dinh: "Re: Help with code to run query and test a field in the record"
- Previous message: PC Data***: "Re: I'm struggling with my limited knowledge of code"
- In reply to: Brian C: "Test for no records returned"
- Next in thread: Cheryl Fischer: "Re: Test for no records returned"
- Messages sorted by: [ date ] [ thread ]