Microsoft ActiveX Data ObjectsMicrosoft ActiveX Data Objects*
*Contents  *Index  *Topic Contents

Description, HelpContext, HelpFile, NativeError, Number, Source, and SQLState Properties Example

This example triggers an error, traps it, and displays the Description, HelpContext, HelpFile, NativeError, Number, Source, and SQLState properties of the resulting Error object.

Public Sub DescriptionX()

	Dim cnn1 As ADODB.Connection
	Dim errLoop As ADODB.Error
	Dim strError As String

	On Error GoTo ErrorHandler
	
	' Intentionally trigger an error.
	Set cnn1 = New ADODB.Connection
	cnn1.Open "nothing"
	
	Exit Sub

ErrorHandler:

	' Enumerate Errors collection and display 
	' properties of each Error object.
	For Each errLoop In cnn1.Errors
		strError = "Error #" & errLoop.Number & vbCr & _
			"	" & errLoop.Description & vbCr & _
			"	(Source: " & errLoop.Source & ")" & vbCr & _
			"	(SQL State: " & errLoop.SQLState & ")" & vbCr & _
			"	(NativeError: " & errLoop.NativeError & ")" & vbCr
		If errLoop.HelpFile = "" Then
			strError = strError & _
				"	No Help file available" & _
				vbCr & vbCr
		Else
			strError = strError & _
				"	(HelpFile: " & errLoop.HelpFile & ")" & vbCr & _
				"	(HelpContext: " & errLoop.HelpContext & ")" & _
				vbCr & vbCr
		End If
			

	Debug.Print strError
	Next

	Resume Next

End Sub

Up Top of Page
© 1997 Microsoft Corporation. All rights reserved. Terms of Use.