-
I wrote this code:
Private Sub txtName_LostFocus()
Call CheckTextValidation(txtName)
End Sub
Public Function CheckTextValidation(txt As TextBox) As Boolean
If txt.Text = Empty Then
Call MsgBox("you should insert data to this field", vbExclamation + vbOKOnly, App.Title)
CheckTextValidation = False
txt.SetFocus
Else
CheckTextValidation = True
End If
End Function
But ,it doesn't work properly after it display the first
msgbox and i clicked OK it display the msgbox AGAIN !!!
PLEASE HELP
-
This is just a guess, but you are giving focus to the wrong textbox. Look at you code. You call the validation when TxtName losses focus, and then give focus back to txt. If these are two separate textboxes, then this is your problem, because TxtName will always be losing focus.
Hope this helps.
-
Try this
That's odd... your code works for me... you can use this simplified method which should work also:
Code:
Dim CheckTextValidation As Boolean
Private Sub txtName_LostFocus()
If txtname.Text = Empty Then
Call MsgBox("you should insert data to this field", vbExclamation + vbOKOnly, App.Title)
CheckTextValidation = False
txtname.SetFocus
Else
CheckTextValidation = True
End If
End Sub
good luck
-
Are there two textboxes you use this method on?
If so, putting pocus back on the first textbox will cause loosing focus for the second, and so on.