Results 1 to 4 of 4

Thread: Question about the Error Provider

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2002
    Posts
    68

    Question about the Error Provider

    Can you use one error provider to validate multiple controls on a form. I am using one on a form that will validate the controls the first time there is an error in the first control but if the error is fixed in the first control and not fixed in the secon control the error provider goes away. Is there something wrong with the code that I have posted below. It checks two text boxes and makes sure that they contain Alpha characters and not Numeric numbers as the first character.



    Private Sub txtAccountName_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtAccountName.Validating

    If IsNumeric(txtAccountName.Text) Then
    ErrorProvider1.SetError(txtAccountName, "Not a numeric value.")
    Else
    ' Clear the error.
    ErrorProvider1.SetError(txtAccountName, "")
    End If


    End Sub

    Private Sub txtIssuingBank_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtIssuingBank.Validating

    If IsNumeric(txtAccountName.Text) Then
    ErrorProvider1.SetError(txtIssuingBank, "Not a numeric value.")
    Else
    ' Clear the error.
    ErrorProvider1.SetError(txtIssuingBank, "")
    End If

  2. #2
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536
    The code you posted checks txtAccount name in both subroutines, ignoring txtIssuingBank. Apart from that, this code looks ok to me.

    VB Code:
    1. Private Sub txtAccountName_Validating(ByVal sender As Object, _
    2. ByVal e As System.ComponentModel.CancelEventArgs) Handles _
    3. txtAccountName.Validating
    4.  
    5. If IsNumeric(txtAccountName.Text) Then
    6. ErrorProvider1.SetError(txtAccountName, "Not a numeric value.")
    7. Else
    8. ' Clear the error.
    9. ErrorProvider1.SetError(txtAccountName, "")
    10. End If
    11.  
    12.  
    13. End Sub
    14.  
    15. Private Sub txtIssuingBank_Validating(ByVal sender As Object, _
    16. ByVal e As System.ComponentModel.CancelEventArgs) Handles _
    17. txtIssuingBank.Validating
    18.  
    19. If IsNumeric([b]txtAccountName.Text[/b]) Then
    20. ErrorProvider1.SetError(txtIssuingBank, "Not a numeric value.")
    21. Else
    22. ' Clear the error.
    23. ErrorProvider1.SetError(txtIssuingBank, "")
    24. End If
    This world is not my home. I'm just passing through.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2002
    Posts
    68
    Thanks trisuglow for catching that error. I thought I fixed it before.

    Thanks

  4. #4
    Addicted Member MasterBlaster's Avatar
    Join Date
    Jul 2002
    Location
    Seattle
    Posts
    196
    Argh, It's much eaiser to keep track of if you validate all your controls in the same spot
    Code:
            Private Sub TextBox_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) _
      Handles txtAccountName.Validating, txtIssuingBank.Validating
                    Dim Control As Windows.Forms.Control = sender
                    If IsNumeric(Control.Text) Then
                        ErrorProvider1.SetError(Control, "Not a numeric value.")
                    Else
                        ' Clear the error.
                        ErrorProvider1.SetError(Control, "")
                    End If
                End Sub
    Last edited by MasterBlaster; Jul 17th, 2003 at 02:16 PM.
    "And most of the evils of society can, in fact, be cured through information. We have a society that has been disinformed and based on the disinformation has made irrational choices. And that's what I mean by 'ignorance.' People, who ordinarily might be smart, are deprived of the data by which to make a rational decision, don't have the data to do it."
    Frank Zappa

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width