ErrorProvider

One of the cool things that I’ve found while playing in VB.Net is the ErrorProvider control. It’s a very “clean” way of giving feedback to the users, without having to bother them with messages or “get in the way” popups.

So I created this class that works in VBA, that basically does the same thing. I didn’t implement it completely (for example, the ErrorProvider control in VB.Net allows you to display errors inside a DataGrid, mine doesn’t, at least for now ;-) )

Here’s a couple of screenshots that I created:

ErrorProvider sample form

Sample for ErrorProvider

It shows the four basic properties (one of which is missing in the .Net version) that can be modified:

  • Blink Rate: Amount of milliseconds between blinks.
  • Blink Style: Can be “Always blink”, “Blink if different error” and “Never blink”
  • Blink Times: This is the one missing in .Net. Number of times that the image should blink.
  • Icon: (Double click on the image to change it). Full path of the image to display (for best results, use a 16 x 16 icon)

Now, how to use the class.

Here’s the code behind the sample userform:

Option Explicit

Dim err1 As CErrorProvider

Private Sub btnOK_Click()
   ‘Validate the name
  If Len(txtName.value) = 0 Then
      err1.SetError txtName, “Please fill this box”
   Else
      err1.SetError txtName, “”
      Unload Me
   End If
End Sub

Private Sub UserForm_Initialize()
   Set err1 = New CErrorProvider
   
   With err1
      .BlinkRate = 100
      .BlinkStyle = AlwaysBlink
      .BlinkTimes = 3
      .Icon = ThisWorkbook.Path & “error.ico”
   End With
End Sub

Here is a link to the file. Enjoy !

Posted in Uncategorized

Leave a Reply

Your email address will not be published. Required fields are marked *