I had a problem to focus back to the same textbox after validation.
I tried setfocus on UserForm_Activate() event it worked fine. But when I use it in TextBox1_Change or Exit Event it did not work.
Also when I add the same validation in a Command_click event to validate the textbox it works when I hit the enter key after I select to command box. But not working when clicking by mouse.
Someone can help?
Following are the code:
Private Sub CommandButton1_Click()
Sheet2.Select
If TB_name.Value = "" Then
MsgBox "name is empty."
Me.Controls("TB_name").SetFocus' not working when click by mouse, but works when by enter key.
Exit Sub
End If
End Sub
Private Sub TB_name_Change()
If UserForm232.TB_name.Value = "" Then
MsgBox "Username can not be empty."
TB_nmae.SetFocus ' not working
End If
End Sub
I tried setfocus on UserForm_Activate() event it worked fine. But when I use it in TextBox1_Change or Exit Event it did not work.
Also when I add the same validation in a Command_click event to validate the textbox it works when I hit the enter key after I select to command box. But not working when clicking by mouse.
Someone can help?
Following are the code:
Private Sub CommandButton1_Click()
Sheet2.Select
If TB_name.Value = "" Then
MsgBox "name is empty."
Me.Controls("TB_name").SetFocus' not working when click by mouse, but works when by enter key.
Exit Sub
End If
End Sub
Private Sub TB_name_Change()
If UserForm232.TB_name.Value = "" Then
MsgBox "Username can not be empty."
TB_nmae.SetFocus ' not working
End If
End Sub