Looking for a slick way to test for an unopened recordset

  • Thread starter Thread starter MyndPhlyp
  • Start date Start date
M

MyndPhlyp

I've tried IsNull() and IsEmpty(), but both return false.

VBA, at least in Access 2000, doesn't like the test:

If rs = Nothing Then ...

Is there an easy way to test an ADODB.Recordset to see if it is Nothing?
 
You can test a variant to see if it is empty,nothing,null or missing.
You can test an object variable to see if it is nothing or same as.

if rs is nothing then set rs = ....

Note: Closing a recordset object does not set the variable to nothing.

(david)
 
david epsom dot com dot au said:
You can test a variant to see if it is empty,nothing,null or missing.
You can test an object variable to see if it is nothing or same as.

if rs is nothing then set rs = ....

Note: Closing a recordset object does not set the variable to nothing.

(david)

That's a VBA syntax I've yet to use ... If <something> IS Nothing. Odd that
VBA would like that test, but doesn't like IF <something> = Nothing. I guess
it sort of makes sense - an object can BE nothing, but since nothing has no
defined value, similar to null or infinity, you can't test for equality. Odd
too that VBA would include IsNull() and IsEmpty(), but not IsNothing().
"Missing" is something I have yet to encounter. When would one use that?

Yes, I am aware that closing a recordset doesn't set it to Nothing.

Thanx for the feedback.
 
"Missing" is something I have yet to encounter. When would one use that?

"MISSING" is what you get when you leave out an Optional Variant Parameter
to a sub/function.

Odd too that VBA would include IsNull() and IsEmpty(), but not
IsNothing().

You're not the only one to think that: check out this quote from the A97
help!

"You can use the IsNothing function determine if an object reference has
been set to Nothing."
(sic)

However, you can see where it came from:

In this case, /IS NOTHING/ is an example of the general expression
result = object1 Is object2

IsEmpty is a function that returns the value of the vartype field of a
variant. An equivalent function is IsObject. You can only test "if an
Object is Nothing" after you first test "if a variant is an object".

if IsObject(v) = true then
if v Is Nothing then

'Nothing' has been defined as an object, not as a vartype.

In a language where objects are the fundamental variable type, this
distinction disappears.

(david)
 
david epsom dot com dot au said:
"MISSING" is what you get when you leave out an Optional Variant Parameter
to a sub/function.


IsNothing().

You're not the only one to think that: check out this quote from the A97
help!

"You can use the IsNothing function determine if an object reference has
been set to Nothing."
(sic)

However, you can see where it came from:

In this case, /IS NOTHING/ is an example of the general expression
result = object1 Is object2

IsEmpty is a function that returns the value of the vartype field of a
variant. An equivalent function is IsObject. You can only test "if an
Object is Nothing" after you first test "if a variant is an object".

if IsObject(v) = true then
if v Is Nothing then

'Nothing' has been defined as an object, not as a vartype.

In a language where objects are the fundamental variable type, this
distinction disappears.

(david)

It is all much more clear now. Thanx again.
 
David:

Thought you might be interested ...

Just the act of testing an ADODB.Recordset to see if it /Is Nothing/ causes
it to not be /Nothing/. Instead, I test rs.ActiveConnection, which seems to
work.

I thought I had lost what little mynd I had left until I fired up the Locals
view and set a couple of breakpoints. Before the test, the ADODB.Recordset
was indeed /Nothing/. Right after the test, it had value even though many of
the Properties were /Nothing/ and several were invalid on a closed
Recordset.
 
Back
Top