Best way to see if recordset exists?

Best way to see if recordset exists?

am 07.03.2005 17:52:28 von Colin Butler

I'm querying an Access database to retrieve information about one record and
then displaying that information in a report. If the contents of a
particular field are not blank I want to query the database again to get
other information to display in the report. If the information does not
exist in the first query, I don't run the second query. If I don't run the
second query, then some of the information I want to display in the report
is not available and the report breaks down. What's the best way to say
something like...if second recordset does not exist don't display data for
this field?

Re: Best way to see if recordset exists?

am 07.03.2005 19:52:48 von reb01501

Colin Butler wrote:
> I'm querying an Access database to retrieve information about one
> record and then displaying that information in a report. If the
> contents of a particular field are not blank I want to query the
> database again to get other information to display in the report. If
> the information does not exist in the first query, I don't run the
> second query. If I don't run the second query, then some of the
> information I want to display in the report is not available and the
> report breaks down. What's the best way to say something like...if
> second recordset does not exist don't display data for this field?

Ummm, the recordset object exists: you seem to be asking how to determine if
your query returned any records. Simple: immediately after opening the
recordset, check its EOF property. If true, then you have an empty
recordset. I've posted many examples of this. A quick browse through the a
week's worth of my postings should get you a few examples.

Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

Re: Best way to see if recordset exists?

am 07.03.2005 22:39:47 von jeff.nospam

On Mon, 07 Mar 2005 16:52:28 GMT, "Colin Butler"
wrote:

>I'm querying an Access database to retrieve information about one record and
>then displaying that information in a report. If the contents of a
>particular field are not blank I want to query the database again to get
>other information to display in the report. If the information does not
>exist in the first query, I don't run the second query. If I don't run the
>second query, then some of the information I want to display in the report
>is not available and the report breaks down. What's the best way to say
>something like...if second recordset does not exist don't display data for
>this field?

Try the EOF method:

If rs.EOF Then
Response.Write "No records returned"
Else
Do your thing...
End If

(Assumes your recordset object is named "rs"...)

Jeff