When an API call is executed in VB and it has an error it usually sets the Err.LastDllError property to a number. You can decode this number to a meaningful description of the error as follows:

VB Code:
  1. '\ API Error decoding
  2. Private 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
  3.  
  4. Public Function LastSystemError() As String
  5.  
  6. Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000
  7. Dim sError As String * 500 '\\ Preinitilise a string buffer to put any error message into
  8. Dim lErrNum As Long
  9. Dim lErrMsg As Long
  10.  
  11. lErrNum = Err.LastDllError
  12.  
  13. lErrMsg = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, ByVal 0&, lErrNum, 0, sError, Len(sError), 0)
  14.  
  15. LastSystemError = Trim(sError)
  16.  
  17. End Function