VBA 与 Microsoft Access - 检查对象是否存在

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7823106/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 12:04:59  来源:igfitidea点击:

VBA With Microsoft Access - Check if object exists

ms-accessvbaactivexwebbrowser-control

提问by JMK

I'm using VBA with Microsoft Access.

我在 Microsoft Access 中使用 VBA。

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

我正在为 WebBrowserControl 中的项目设置一个对象,该对象有时存在,有时不存在。

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.

如果“myDiv”存在,那就太棒了,如果不存在,我希望 Access 让我知道,以便我可以处理它。

回答by JimmyPena

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.

如果在“myDiv”不存在时抛出错误,您可能需要在“Set”语句前加上“On Error Resume Next”。