Is Recordset Set (1 Viewer)

David44Coder

Member
Local time
Tomorrow, 07:12
Joined
May 20, 2022
Messages
100
When mousing over a recordset Name in a Function, a popup shows it "= Nothing".

Debug.print recordset Name gives an error. (91, not set)

Can vba test for this without needing an error handler?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:12
Joined
May 7, 2009
Messages
16,810
since the there Is No Recordset Object, then the variable that holds it is set to Nothing.
outputing it's Name (or the SQL string) will give you error since the Object does not exists.
you should always use Error Handler, if you don't and your code has Error you will get Error and may cause
your db not to work.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 14:12
Joined
Feb 28, 2001
Messages
23,151
VBA can test using IF recordset-variable IS Nothing, which will return True or False.

EDIT: arnelgp is not wrong about the advisability of having error handlers in place, though there is a direct answer to your question, which I gave you.
 

David44Coder

Member
Local time
Tomorrow, 07:12
Joined
May 20, 2022
Messages
100
Thanks for the answers. Doc_Man I have that working and like it. I follow the error logic, but didn't think this was an error.
Only if its Set does a certain routine have to run. and If the popup can interpret it, perhaps the code should as well. But I totally get what arnelgp means.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 20:12
Joined
Sep 12, 2006
Messages
14,901
maybe it's for the above reasons - most examples I see test for the negative

Code:
if not myrecordset is nothing then
    use myrecordset
end if
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 15:12
Joined
Feb 19, 2002
Messages
36,871
Most people find it easier to read positive criteria than negative.

Code:
If myrecordset is nothing Then
    Msgbox "some message"
    Exit Sub
End If
 

Users who are viewing this thread

Top Bottom