This is a VALIDATION problem.... So use the VALIDATING and VALIDATED events for the textbox in question....
Do not do the looping check you wrote which I assume you have placed in the button click event.
First create a module level boolean variable to indicated if valid data is available.
private m_DataValid as boolean 'this will be initialized to false upon form load
this boolean will be set or cleared by the validation events and will be checked by the button click event with an IF ElSE THEN statement.
The Validating event fires when the user attempts to leave the check box. This is where you test to see if you have a "" or null
dim strTest as string
strTest = myTextbox.text.trim
'trim removes all whitespace from the text like spaces
this prevents a space from being detected
you can now test several ways
Test for a "" string if strTest = ""
OR test the string lenght is greater than 0
IF strTest.leght > 0
If your tests pass then set
m_DataValid = TRUE
Now if your test fails meaning nothing has been typed you do a few things.
1.) Set your module level variable m_DataValid = FALSE
2.) alert the user with a message box and give them an option to ignore and leave anyway. They may be trying to exit the program.
3.) Depending on the results of the message box you will set the e.cancel property TRUE or FALSE
TRUE = Cancle the attempted move the focus will not shift from the text box
FALSE = Do Not Cancle the attempted move , Focus WILL shift to the next control
You can easily incorporate bells and whistles like changing textbox background colors based upon focus (Yellow) Error(pink) and VALIDATED data (white ir good, ReD if BAD)
The Button Click event now only has to check the m_DataValid
IF m_DataValid THEN
'allow the up date
Else
'Alert the user to place valid text in text box
exit sub
END IF