Visual Basic Language Reference  

LastDLLError Property

Returns a system error code produced by a call to a dynamic-link library (DLL). Read-only.

ReadOnly Property LastDLLError() As Integer

Remarks

The LastDLLError property applies only to DLL calls made from Visual Basic code. When such a call is made, the called function usually returns a code indicating success or failure, and the LastDLLError property is filled. Check the documentation for the DLL's functions to determine the return values that indicate success or failure. Whenever the failure code is returned, the Visual Basic application should immediately check the LastDLLError property. No exception is raised when the LastDLLError property is set.

Example

When pasted into a UserForm module, the following code causes an attempt to call a DLL function. The call fails because the argument that is passed in (a null pointer) generates an error, and in any event, SQL can't be cancelled if it isn't running. The code following the call checks the return of the call, and then prints at the LastDLLError property of the Err object to reveal the error code. On systems without DLLs, LastDLLError always returns zero.

Private Declare Function SQLCancel Lib "ODBC32.dll" _
(ByVal hstmt As Long) As Integer

Private Sub Update()
   Dim RetVal As Integer
   Dim myhandle As Long
   ' Call with invalid argument.
   RetVal = SQLCancel(myhandle)
   ' Check for SQL error code.
   If RetVal = -2 Then
      ' Display the information code.
      MsgBox("Error code is :" & Err.LastDllError) 
    End If
End Sub

See Also

Declare Statement | Description Property | Err Object | ErrorToString Function | HelpContext Property | HelpFile Property | Number Property | Source Property

Applies To

Err Object