QuickStart: The Vista-style Error Dialog

 Sept 2010: v2 of VBA Global Error Handler is now available vbWatchdog (no DLLs!)

What is the Vista-style error dialog?

In place of the old VBE error dialog, we have provided a new-look Vista-style error dialog that uses the new features of our Global Error Handler. It also happens to be very customizable! (discussed below).

To show the Vista dialog, call it from your global error handler like this:

Public Sub MyGlobalErrorHandler()

    ErrEx.State = ErrEx.ShowErrorDialog()

End Sub

The Vista-style dialog is also fully backwards compatible with non-Vista operating systems.

Customizing the Vista-style error dialog

To customize the Vista-style dialog, use the ErrEx.DialogOptions object included in the SimplyVBA Global error handler library.

This picture highlights the majority of customizable properties exposed by ErrEx.DialogOptions:

Customizable Vista Dialog

Other properties:

ButtonsAsCommandLinks (Boolean), which defines whether or not the dialog uses the buttons arranged horizontally (as above), or buttons arranged vertically (like hyperlinks).  Default value is False (as above).

TruncateLinesAtCount (Long) - defines the cut off point (count of characters) at which long lines are truncated (with elipses '...' appended).

Customizing buttons

Our Vista-style dialog accepts two types of buttons: standard and custom. Standard buttons should be used for the normal features of your error dialog (such as offering 'close', 'debug', 'ignore & continue' buttons). Custom buttons should be used for expanding the functionality further - e.g. by offering a 'search internet for this error' button or a 'send the error log to administrator' button.

To start with, you need to clear the default buttons using ErrEx.DialogOptions.RemoveAllButtons, then you need to add your buttons.

For standard buttons use ErrEx.DialogOptions.AddButton("Button Name", BUTTONACTION). BUTTONACTION can be any one of the following constants:

  • BUTTONACTION_ONERROREND - use for 'Close' / 'End' buttons
  • BUTTONACTION_ONERRORDEBUG - use for 'Debug sourcecode' buttons
  • BUTTONACTION_ONERRORRESUMENEXT - use for 'Resume' or 'Ignore and continue' buttons
  • BUTTONACTION_ONERROREXITPROCEDURE - use for 'Exit Procedure' buttons
  • BUTTONACTION_ONERRORRETRY - use for 'Retry' type buttons
  • BUTTONACTION_SHOWHELP - use for 'Help' buttons
  • BUTTONACTION_SHOWVARIABLES - use for showing the Variables window dump

If you need to add a custom button, you do this with ErrEx.DialogOptions.AddCustomButton("Button Name", "CallbackProcedureName"). CallbackProcedureName is the name of a public procedure that you have defined. It can be declared with a simple subroutine like this:

Public Sub CallbackProcedureName()
    ' Do something
End Sub

The above method is used when you don't want the error dialog to close but just want to do something when the user clicks the button - e.g. you might want to open an internet search window that looks for details on the error number that occurred. If you want the error dialog to close once you've done something, then you declare the procedure slightly differently:

Public Function CallbackProcedureName() As OnErrorStatus
    ' Do something here... e.g. send an e-mail to the developer / administrator
    ' The return value of this function will be passed on as the return value to ErrEx.ShowErrorDialog
    CallbackProcedureName = OnErrorEnd
End Function

For an example of using the callback method, see the Sample.mdb included with the installation.

An example:

    With ErrEx.DialogOptions
        .WindowTitleText = ApplicationName & " - runtime error"
        .WindowFooterText = "powered by the SimplyVBA Global Error Handler"
        .CallStackVisible = True
        ' Remove any default buttons from the Vista dialog
        ' Add a custom callback button which is used to search the internet for further info
        .AddCustomButton "Search internet", "OnSearchInternet"
        ' Now add our standard buttons
        .AddButton "Show Variables", BUTTONACTION_SHOWVARIABLES
        .AddButton "Debug sourcecode", BUTTONACTION_ONERRORDEBUG
        .AddButton "Ignore and continue", BUTTONACTION_ONERRORRESUMENEXT
        .AddButton "Help", BUTTONACTION_SHOWHELP
        .AddButton "Close", BUTTONACTION_ONERROREND
        ' We want "Close" to be our default button.  (zero based index from left to right)
        .DefaultButtonNumber = 5
    End With

Customizing the Variables Dump window

The variables dump window is the window that appears after pressing the 'Show Variables' button on the Vista style error dialog:

Variables dump window

To customize this window, you currently have two self explanatory properties:

ErrEx.DialogOptions.VariablesDumpCloseButtonText (string, button caption)
ErrEx.DialogOptions.VariablesDumpWindowTitle (string, window caption)