There are 10 textbox in userform and one command button.why bother with that if a user can tab out or use mouse to click out? Wouldn't you need to cover all situations? If yes, you could use the control's exit event and cancel it if the control has no value.
Option Explicit
Private Sub CommandButton1_Click()
Dim ctrl As Control ' CREATE A CONTROL OBJECT.
' LOOP THROUGH EACH CONTROL, CHECK IF THE CONTROL IS A TEXTBOX.
For Each ctrl In Me.Controls
If TypeName(ctrl) = "TextBox" Then
If ctrl.Value = "" Then
ctrl.SetFocus
MsgBox "All Textboxes must have data !", vbCritical, "Error"
Exit Sub
End If
End If
Next ctrl
End Sub
Thanks for your time dear .. But i was try this.. it dose not work like i want.Paste the following in the UserForm:
VBA Code:Option Explicit Private Sub CommandButton1_Click() Dim ctrl As Control ' CREATE A CONTROL OBJECT. ' LOOP THROUGH EACH CONTROL, CHECK IF THE CONTROL IS A TEXTBOX. For Each ctrl In Me.Controls If TypeName(ctrl) = "TextBox" Then If ctrl.Value = "" Then ctrl.SetFocus MsgBox "All Textboxes must have data !", vbCritical, "Error" Exit Sub End If End If Next ctrl End Sub
i was just addThat doesn't answer my question about how this stops anyone from using mouse or tab key.
I guess try this in the keydown event for the textbox then
If KeyCode = 13 Then KeyCode = 0
If TextBox6.Value = "" Then
If KeyCode = 13 Then KeyCode = 0
End If