When producing a product, you obviously want to be told about any problems the user finds. However, unless there is an easy way to do this, it is unlikely they will bother. The code below enables you to provide the option to automatically email the developer (you) the error.
Public Declare Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" _
(ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Private Sub cmdCreateError_Click()
On Error GoTo errhandler
'// create an error
Err.Raise 13
errhandler:
ReportError "An Error Occured" & vbCrLf &
"Err " & Err & vbCrLf & Error
End Sub
Private Sub ReportError(ByVal strErrorMessage As String)
If MsgBox(strErrorMessage & vbCrLf & vbCrLf &
"Do you want to email a developer with this error?", vbCritical +
vbYesNo) = vbNo Then Exit Sub
'Replace CRLF with %0d token to give proper line breaks
strErrorMessage = Replace(strErrorMessage, vbCrLf, "%0d")
ShellExecute hwnd, "open", "mailto:[email protected]"
& _
"?subject=Developers Pad Error"
& _
"&body=" & strErrorMessage,
_
"", "", vbNormalFocus
End Sub
Comments