could someone give me the routine for getting the last error.
Printable View
could someone give me the routine for getting the last error.
Within the context of an API call, the last error is held in VB's intrinsic Err.LastDllError member.
To transalate that into a sensible error message:
Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageA" (ByVal dwFlags As Long, lpSource As Any, ByVal dwMessageId As Long, ByVal dwLanguageId As Long, ByVal lpBuffer As String, ByVal nSize As Long, Arguments As Long) As Long
Public Function LastSystemError() As String
Const FORMAT_MESSAGE_FORM_SYSTEM = &H1000
Dim sError As String * 500
Dim lErrMsg As Long
lErrMsg = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, ByVal 0&, Err.LastDllError, sError, Len(sError), 0)
LastSystemError = Trim$(sError)
End Function
HTH,
D.