Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA With Microsoft Access - Check if object exists

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.

like image 727
JMK Avatar asked Oct 19 '11 14:10

JMK


1 Answers

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.

like image 172
JimmyPena Avatar answered Dec 02 '22 05:12

JimmyPena