How to check if an Object Variable is Nothing

M

Mota

Hi;
I need to know if a Recordset Variable (Rst) or another object variable
(such as Microsoft Agent Variable) is referencing to an object or set to
nothing.The IsObject Function returns True even if the Rst is nothing.So how
to know if we have a reference to the Object in our references collection
(Not IsMissing(Rst)) but its variable contains Nothing.Can any one plz help
me?
Thank you in advance.
 
S

Sandra Daigle

If rst is nothing then
msgbox "It is nothing"
else
msgbox "It is something"
endif

More often, I'll check the negative condition

if not rst is nothing then
msgbox "it is something"
endif
 
M

Mota

Thank you Sandra;
Does it heve limitations to use or conditions giving wrong answer?
For example,if for some reasons exceptionally Rst is not set yet,does it
works right?Or any other risks?
Thanx again.

Sandra Daigle said:
If rst is nothing then
msgbox "It is nothing"
else
msgbox "It is something"
endif

More often, I'll check the negative condition

if not rst is nothing then
msgbox "it is something"
endif


--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

Hi;
I need to know if a Recordset Variable (Rst) or another object
variable (such as Microsoft Agent Variable) is referencing to an
object or set to nothing.The IsObject Function returns True even if
the Rst is nothing.So how to know if we have a reference to the
Object in our references collection (Not IsMissing(Rst)) but its
variable contains Nothing.Can any one plz help me?
Thank you in advance.
 
S

Sandra Daigle

None that I'm aware of - I use it to prevent errors when there is a
possiblity of certain object variables going out of scope or not being
defined - it works well in every case where I've used it.

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

Thank you Sandra;
Does it heve limitations to use or conditions giving wrong answer?
For example,if for some reasons exceptionally Rst is not set yet,does
it works right?Or any other risks?
Thanx again.

Sandra Daigle said:
If rst is nothing then
msgbox "It is nothing"
else
msgbox "It is something"
endif

More often, I'll check the negative condition

if not rst is nothing then
msgbox "it is something"
endif


--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

Hi;
I need to know if a Recordset Variable (Rst) or another object
variable (such as Microsoft Agent Variable) is referencing to an
object or set to nothing.The IsObject Function returns True even if
the Rst is nothing.So how to know if we have a reference to the
Object in our references collection (Not IsMissing(Rst)) but its
variable contains Nothing.Can any one plz help me?
Thank you in advance.
 
M

Mota

Ok,Thank you.

Sandra Daigle said:
None that I'm aware of - I use it to prevent errors when there is a
possiblity of certain object variables going out of scope or not being
defined - it works well in every case where I've used it.

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

Thank you Sandra;
Does it heve limitations to use or conditions giving wrong answer?
For example,if for some reasons exceptionally Rst is not set yet,does
it works right?Or any other risks?
Thanx again.

Sandra Daigle said:
If rst is nothing then
msgbox "It is nothing"
else
msgbox "It is something"
endif

More often, I'll check the negative condition

if not rst is nothing then
msgbox "it is something"
endif


--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.


Mota wrote:
Hi;
I need to know if a Recordset Variable (Rst) or another object
variable (such as Microsoft Agent Variable) is referencing to an
object or set to nothing.The IsObject Function returns True even if
the Rst is nothing.So how to know if we have a reference to the
Object in our references collection (Not IsMissing(Rst)) but its
variable contains Nothing.Can any one plz help me?
Thank you in advance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top