• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Applying same validation to multiple textboxes

Tripp

Member
Hello,

I am wondering if there is a way to apply a text box validation to all the text boxes on my userform. I have a working validation and I can apply it individually, but if I want to add lots more text boxes this wouldn't be very practical.

So is there a way to cycle through all the text boxes and apply this validation?

Regards,

Tripp

Code:
Private Sub TextBox_Exit(ByVal cancel As MSForms.ReturnBoolean)

           
    If IsNumeric(NameTextBox.Text) Or NameTextBox.Value = "" Then
                TB1.BackColor = &HFF&
                MsgBox "Wrong"
                cancel = True
            Else
                TB1.BackColor = &H80000005
    End If
   
    If IsNumeric(DateTextBox.Text) Or DateTextBox.Value = "" Then
                TB1.BackColor = &HFF&
                MsgBox "Wrong"
                cancel = True
            Else
                TB1.BackColor = &H80000005
    End If
   
    If IsNumeric(SiteTextBox.Text) Or SiteTextBox.Value = "" Then
                TB1.BackColor = &HFF&
                MsgBox "Wrong"
                cancel = True
            Else
                TB1.BackColor = &H80000005
    End If
   
End Sub
 
After some digging it looks like I have to have them as separate subs as the "_Exit" is needed for each textbox to trigger the validation.
 
Back
Top