Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What's an easy way to get feedback and/or error messages to tables for future reference?

Functions

What's an easy way to get feedback and/or error messages to tables for future reference?

by  AlanJordan  Posted    (Edited  )
I adapt this code to several different routines including:
LogAMessage, LogAuditInfo, LogProcessInfo and LogAMessage. Perhaps it will also be helpful to you.

Code:
Function LogUserComment(Optional strMsg As String, Optional strKKLogin As String, Optional strPgmrsComments As String, Optional strUrgencyLevel As String, _
    Optional dblProcessingTime As Double, Optional dblOtherStat As Double) As Boolean
        
On Error GoTo errLAM
Dim strSQL As String
        Dim db As Database
        If IsMissing(strMsg) Then strMsg = """"
        If IsMissing(strKKLogin) Then strKKLogin = """"
        If IsMissing(strPgmrsComments) Then strPgmrsComments = """" Else strPgmrsComments = Chr(34) & strPgmrsComments & Chr(34)
        If IsMissing(strUrgencyLevel) Then strUrgencyLevel = """" Else strUrgencyLevel = Chr(34) & strUrgencyLevel & Chr(34)
        Set db = CurrentDb
        strSQL = "INSERT INTO UserComments (Message, KKLoginOrName, ProgrammerComments, UrgencyLevel,ProcessingTime, OtherStat) Values ( """ & strMsg & """,'" & strKKLogin & "'," & _
         strPgmrsComments & "," & strUrgencyLevel & "," & dblProcessingTime & "," & dblOtherStat & ")"
        'debug.print strSQL
        DoCmd.SetWarnings False
        CurrentDb.Execute (strSQL)

        DoCmd.SetWarnings True
        Set db = Nothing
        LogUserComment = True
Exit Function
errLAM:
    LogUserComment = False
    Select Case Err.Number
        Case 3075
            MsgBox "Please reenter your message.  Do not use quote marks. Thank you.", vbInformation
            
            Exit Function
        Case Else
            
            ErrBox ("The problem originated in the function LogUserComment in modUtilities.")
    End Select
End Function

Here's the ErrBox Function
Code:
Public Sub ErrBox(Optional varProblemType As Variant, Optional strUrgencyLevel As String, Optional dblNumRef1 As Double, Optional dblNumRef2 As Double)
'Note:  The case functionality has been anticipated, but no differentiation is made yet.
'FU
Dim strMsg As String

    If IsNull(varProblemType) Then 'there is a type of problem indicated
            strMsg = "There is a problem.  It is " & Err.Number & " - " & Err.Description & " -  Source: " & Err.Source & "."
            MsgBox strMsg
    Else
            Select Case varProblemType
            Case "FL"
               strMsg = "There is a problem.  It is " & Err.Number & " - " & Err.Description & " -  Source: " & Err.Source & "." _
               & vbCrLf & vbCrLf & "Note:  Tell a programmer that the problem originated while loading the form."
            Case 1
                strMsg = "There is a problem.  It is " & Err.Number & " - " & Err.Description & " -  Source: " & Err.Source & "."
            Case 2
                strMsg = "There is a problem.  It is " & Err.Number & " - " & Err.Description & "."
            Case Else
                strMsg = "There is a problem.  It is " & Err.Number & " - " & Err.Description & " -  Source: " & Err.Source & "."
            End Select
            MsgBox strMsg
            Call LogAMessage(strMsg, , CStr(varProblemType), "", dblNumRef1, dblNumRef2)
    End If
End Sub
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top