Returns a system error code produced by a call to a dynamic-link library (DLL). Read-only.
ReadOnly Property LastDLLError() As Integer
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.
Note The LastDllError property requires unmanaged code permission, which may affect its execution in partial trust situations. For more information, see SecurityPermission and Code Access Permissions.
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 Integer) As Long Private Sub Update() Dim RetVal As Integer Dim myhandle As Integer ' 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
Smart Device Developer Notes
This property always returns zero.
Assembly: Microsoft Visual Basic .NET Runtime (in Microsoft.VisualBasic.dll)