Home All Groups Group Topic Archive Search About

How do I know if a RecordSet is open?

Author
28 Feb 2007 10:53 PM
kramer31
Is there a way to determine of a Recordset object is open even if it
hasn't been created with a Command object (but just via
conn.Execute(query))?

Thanks.

Author
1 Mar 2007 2:42 AM
MikeD
"kramer31" <kramer.newsrea***@gmail.com> wrote in message
news:1172703205.055714.265700@m58g2000cwm.googlegroups.com...
> Is there a way to determine of a Recordset object is open even if it
> hasn't been created with a Command object (but just via
> conn.Execute(query))?

If (oRS.State And adStateOpen) = adStateOpen Then
    'recordset is open
Else
    'recordset is closed
End If

The State property is a bitmask so you should always mask the bit you're
wanting to check.  For example, in an asynchronous operation, the state
could be a combination of adStateOpen and any of adStateConnecting,
adStateExecuting, or adStateFetching.

Too often, you'll see code like this:

If oRS.State = adStateOpen Then

This is NOT correct and COULD lead to bugs.

It's irrelevant how the Recordset object got created.

--
Mike
Microsoft MVP Visual Basic