Object = Nothing

Todd Bardoni

Well-known Member
Joined
Aug 29, 2002
Messages
3,042
How do I trap or test for an error where the object equals nothing?

Code:
Set OrderDetail = .document.all.Item("link_to_j26_button")
x = OrderDetail.Click
 

tusharm

MrExcel MVP
Joined
May 28, 2002
Messages
11,007
"Is Nothing," as in

if x is nothing then

or

if not (x is nothing) then
 

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
7,417
Office Version
2016
Platform
Windows
How about...


Code:
Set OrderDetail = .document.all.Item("link_to_j26_button")
If OrderDetail Is Nothing Then
    'Continue here....
End If
x = OrderDetail.Click
 

Todd Bardoni

Well-known Member
Joined
Aug 29, 2002
Messages
3,042
I did and it doesn't work. I get that error message that says something about not having the block end if/with. And when i hit help it says the error was generated by an object being nothing. Then it says to re set it. But I don't know what exactly that means. re-set it to what? I just want to test if the object exists but I'm having a hard time. i could use On Error Goto...but this is in a loop and when it comes back around it triggers the Debug dialog box. If I use on Error resume next, then I get some results that I do not want. So, it would seem my only alternative is to test for it but the If statement doesn't work...
 

Todd Bardoni

Well-known Member
Joined
Aug 29, 2002
Messages
3,042
Ugh, never mind...

I had:-
If OrderDetail = Nothing then...


It should be as Jaafar points out, Is Nothing...

Ughhh....
 

Forum statistics

Threads
1,078,101
Messages
5,338,242
Members
399,215
Latest member
jsowa

Some videos you may like

This Week's Hot Topics

Top