Is Recordset Set

David44Coder

Member
Local time
Today, 15:14
Joined
May 20, 2022
Messages
137
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?
 
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.
 
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.
 
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.
 
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
 
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

Back
Top Bottom