ErrReport DLL 
Questions and Answers

Is the source code available?

Yes, the source code is available for purchase.  Send an e-mail to emunews@msn.com for pricing details.

------------------------------------------------

I'm using ADO.  Is there a way to include all the errors in the ADO error collection in the error report?

Yes, use the CustomInfo property for this.  Just copy and paste the following code into your project and use it to set CustomInfo before you call the ErrorReport method.

Public Function GetADOErrInfo(ByVal MyConnection As ADODB.MyConnection) As String
'*****************************************************************
'* This function returns a formatted error message consisting of *
'* all errors in MyConnection's error collection.  To be used    *
'* in conjunction with ErrReport's CustomInfo property.          *
'*****************************************************************
  Const RIGHT_COL_LEN As Long = 16  'the length of the right column
  Dim objError As ADODB.Error
  Dim lngErrorCount As Long
  Dim strErrInfo As String

  'make sure connection is valid
  If MyConnection Is Nothing Then
    strErrInfo = PadRight("Total ADO Errors:", RIGHT_COL_LEN) & "0" & vbCrLf
  Else
    strErrInfo = PadRight("Total ADO Errors:", RIGHT_COL_LEN) & CStr(MyConnection.Errors.Count)
    For Each objError In MyConnection.Errors
      lngErrorCount = lngErrorCount + 1
      With objError
        strErrInfo = strErrInfo & vbCrLf
        strErrInfo = strErrInfo & vbCrLf & PadRight("Error Number:", RIGHT_COL_LEN) & CStr(lngErrorCount)
        strErrInfo = strErrInfo & vbCrLf & PadRight("Description:", RIGHT_COL_LEN) & .Description
        strErrInfo = strErrInfo & vbCrLf & PadRight("Number:", RIGHT_COL_LEN) & CStr(.Number)
        strErrInfo = strErrInfo & vbCrLf & PadRight("NativeError:", RIGHT_COL_LEN) & CStr(.NativeError)
        strErrInfo = strErrInfo & vbCrLf & PadRight("Source:", RIGHT_COL_LEN) & .Source
        strErrInfo = strErrInfo & vbCrLf & PadRight("SQLState:", RIGHT_COL_LEN) & .SQLState
      End With
    Next objError
  End If

  GetADOErrInfo = strErrInfo

End Function

------------------------------------------------

Does the ErrReport DLL work with VBA applications such as within Excel, Word or Access?

Not currently.  I don't do much VBA work but I'm looking into adding VBA support in a future release.

------------------------------------------------

We use ErrReport DLL for all our business applications and would rather have the error reports logged to a central database such as Access or SQL Server instead of a text file.  This will let us run queries and reports based on the information ErrReport collects for us.  Can you add this feature to ErrReport?

This is certainly a great idea but it's beyond the scope of my project.  One of the key design goals for ErrReport DLL was to make it truly general purpose, regardless of the type of project.  Visual Basic can be used for almost any type of programming task - standard business applications, utilities, computer games or even screen savers.  Adding database support doesn't make sense for certain types of applications.  However, I am selling the source code.  This will allow you to customize ErrReport to your specific needs and add whatever functionality you want.  For pricing details, send an e-mail to emunews@msn.com.

------------------------------------------------

Is there an add-in or utility that can insert the error handling code for me?

No.

------------------------------------------------

When I use the LineNumber feature, the line number is always 0 in the error report.  What am I doing wrong?

ErrReport's LineNumber feature is unsupported, however, it should work.  If the line number is always zero, most likely your source code doesn't have line numbers in them. 

------------------------------------------------

I love all the diagnostic information ErrReport DLL gives me but I want more!

This isn't really a question but you can try out this function.  It will iterate through all the controls on a form and return the contents of each recognized control.  Just copy and paste the following code into your project and use it to set CustomInfo before you call the ErrorReport method.

Public Function GetControlState(ByVal MyForm As Form) As String
'*****************************************************************
'* This function returns a formatted message showing the current *
'* state of input controls on a form.  To be used in conjunction *
'* with ErrReport's CustomInfo property.                         *
'*****************************************************************
  Const MAX_CHARS_PER_LINE As Long = 54
  Const RIGHT_COL_LEN As Long = 16  'the length of the right column
  Dim objControl As Control
  Dim strInfo As String
  Dim strValue As String
  
  strInfo = strInfo & vbCrLf & String$(MAX_CHARS_PER_LINE, "_")
  strInfo = strInfo & vbCrLf & "  C O N T R O L   S T A T E   I N F O R M A T I O N"
    
  For Each objControl In MyForm.Controls
    Select Case TypeName(objControl)
      Case "CheckBox"
        strInfo = strInfo & vbCrLf & vbCrLf & PadRight("Name:", RIGHT_COL_LEN) & objControl.Name
        If objControl.Value = vbChecked Then
          strValue = "vbChecked"
        ElseIf objControl.Value = vbGrayed Then
          strValue = "vbGrayed"
        Else
          strValue = "vbUnchecked"
        End If
        strInfo = strInfo & vbCrLf & PadRight("Value:", RIGHT_COL_LEN) & strValue
      Case "ComboBox"
        strInfo = strInfo & vbCrLf & vbCrLf & PadRight("Name:", RIGHT_COL_LEN) & objControl.Name
        strInfo = strInfo & vbCrLf & PadRight("Text:", RIGHT_COL_LEN) & objControl.Text
        strInfo = strInfo & vbCrLf & PadRight("ListIndex:", RIGHT_COL_LEN) & CStr(objControl.ListIndex)
      Case "DirListBox"
        strInfo = strInfo & vbCrLf & vbCrLf & PadRight("Name:", RIGHT_COL_LEN) & objControl.Name
        strInfo = strInfo & vbCrLf & PadRight("ListIndex:", RIGHT_COL_LEN) & CStr(objControl.ListIndex)
      Case "DriveListBox"
        strInfo = strInfo & vbCrLf & vbCrLf & PadRight("Name:", RIGHT_COL_LEN) & objControl.Name
        strInfo = strInfo & vbCrLf & PadRight("ListIndex:", RIGHT_COL_LEN) & CStr(objControl.ListIndex)
        strInfo = strInfo & vbCrLf & PadRight("Drive:", RIGHT_COL_LEN) & CStr(objControl.Drive)
      Case "FileListBox"
        strInfo = strInfo & vbCrLf & vbCrLf & PadRight("Name:", RIGHT_COL_LEN) & objControl.Name
        strInfo = strInfo & vbCrLf & PadRight("ListIndex:", RIGHT_COL_LEN) & CStr(objControl.ListIndex)
      Case "HScrollBar"
        strInfo = strInfo & vbCrLf & vbCrLf & PadRight("Name:", RIGHT_COL_LEN) & objControl.Name
        strInfo = strInfo & vbCrLf & PadRight("Value:", RIGHT_COL_LEN) & CStr(objControl.Value)
      Case "ListBox"
        strInfo = strInfo & vbCrLf & vbCrLf & PadRight("Name:", RIGHT_COL_LEN) & objControl.Name
        strInfo = strInfo & vbCrLf & PadRight("Text:", RIGHT_COL_LEN) & objControl.Text
        strInfo = strInfo & vbCrLf & PadRight("ListIndex:", RIGHT_COL_LEN) & CStr(objControl.ListIndex)
      Case "OptionButton"
        strInfo = strInfo & vbCrLf & vbCrLf & PadRight("Name:", RIGHT_COL_LEN) & objControl.Name
        If objControl.Value = True Then
          strValue = "True"
        Else
          strValue = "False"
        End If
        strInfo = strInfo & vbCrLf & PadRight("Value:", RIGHT_COL_LEN) & strValue
      Case "TextBox"
        strInfo = strInfo & vbCrLf & vbCrLf & PadRight("Name:", RIGHT_COL_LEN) & objControl.Name
        strInfo = strInfo & vbCrLf & PadRight("Text:", RIGHT_COL_LEN) & objControl.Text
      Case "VScrollBar"
        strInfo = strInfo & vbCrLf & vbCrLf & PadRight("Name:", RIGHT_COL_LEN) & objControl.Name
        strInfo = strInfo & vbCrLf & PadRight("Value:", RIGHT_COL_LEN) & CStr(objControl.Value)
    End Select
  Next objControl
  
  GetControlState = strInfo

End Function

------------------------------------------------

Both GetADOErrInfo and GetControlState are using a function called PadRight.  Where can I find this?

Right here:

Public Function PadRight(ByVal MyText As String, ByVal Length As Long, _
  Optional ByVal Character As String = " ") As String
'*****************************************************************
'* This function will right pad a string with a given character  *
'* so that the string is the desired length.  If the string      *
'* exceeds this length, the string is returned unmodified.       *
'*****************************************************************
  If Len(MyText) < Length Then
    PadRight = MyText & String$(Length - Len(MyText), Character)
  Else
    PadRight = MyText
  End If

End Function