适用于:Access 2013、Office 2013
返回一个数字值,该值指定错误。
语法
表达式 。数量
表达 一个代表 Error 对象的变量。
备注
使用 Number 属性确定发生了哪种错误。 该属性的值是与错误条件对应的唯一陷阱号。
示例
以下示例强制生成一个错误,然后捕获错误,并显示生成的 Error 对象的 Description、Number、Source、HelpContext 和 HelpFile 属性。
Sub DescriptionX()
Dim dbsTest As Database
On Error GoTo ErrorHandler
' Intentionally trigger an error.
Set dbsTest = OpenDatabase("NoDatabase")
Exit Sub
ErrorHandler:
Dim strError As String
Dim errLoop As Error
' Enumerate Errors collection and display properties of
' each Error object.
For Each errLoop In Errors
With errLoop
strError = _
"Error #" & .Number & vbCr
strError = strError & _
" " & .Description & vbCr
strError = strError & _
" (Source: " & .Source & ")" & vbCr
strError = strError & _
"Press F1 to see topic " & .HelpContext & vbCr
strError = strError & _
" in the file " & .HelpFile & "."
End With
MsgBox strError
Next
Resume Next
End Sub