-
Textbox Validation
I have 13 textboxes in a userform. I want to check if at least 1 textbox has a value. If at least 1 textbox has a value, then do nothing. If neither textboxes has a value then display a msgbox only once. I'm using this code below, but it displays the msgbox for each textbox that is empty and displays the msgbox even if all the textboxes are filled...
[vba]
Private Sub Enter_Click()
Dim Ctrl As Control
For Each Ctrl In Me.Controls
If InStr(1, Ctrl.Name, "TextBox") > 0 Then
MsgBox "No Value entered" ' Display the text
End If
Next
End Sub
[/vba]
Last edited by av8tordude; 11-08-2012 at 10:22 AM.
-
Use End For after MsgBox.
-
Ok that help, but now it displays the msgbox even if all the textboxes are filled...
-
[VBA]Private Sub CommandButton1_Click()
TextBoxesBlank
Unload Me
End Sub
Private Sub TextBoxesBlank()
Dim Ctrl As msforms.Control, tf As Boolean
tf = True
For Each Ctrl In Me.Controls
If VarType(Ctrl) = 8 And Ctrl.Value <> "" Then
tf = False
Exit For
End If
Next
If tf Then MsgBox "All textbox values are empty."
End Sub[/VBA]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules