VBA With Microsoft Access - Check if object exists

54,479

I believe it would be something like

If myItemInsideWebpage Is Nothing Then
' doesn't exist
Else
' does exist
End If

You may need to preface your 'Set' statement with 'On Error Resume Next' in case an error is thrown when 'myDiv' does not exist.

Share:
54,479
JMK
Author by

JMK

Software developer currently living in Belfast, jack of a couple of trades, master of none!

Updated on March 06, 2020

Comments

  • JMK
    JMK about 4 years

    I'm using VBA with Microsoft Access.

    I'm setting an object to an item inside a WebBrowserControl that sometimes exists, sometimes doesn't.

    Dim myWebBrowser As Object
    Dim myItemInsideWebpage As Object
    
    Set myWebBrowser = Me.WebBrowser0.Object
    Set myItemInsideWebpage = myWebBrowser.Document.GetElemendById("myDiv")
    

    If 'myDiv' exists, awesome, if not I want Access to let me know so I can deal with it.