Dim ChkID As String
ChkID = txtCustomer.Text
If ChkID = "" Then
Message = "Please fill in the Customer ID Number"
MsgBox Message, vbOKOnly + vbInformation, "ERROR"
End If
You don't. Assuming this is valiadtion, you issue the error message then exit the sub after the user acknowledges. The user can not enter data as long as the MsgBox is displayed.
Maybe I should have worded it differently. How do I get the program to loop back to the begining until something is entered in txtCustomer.Text field? I only want the error to pop up if there is nothing in that field. If nothing is there, loop back until something is there, else go on with the program.
You really don't need to loop through this like JohnYingling said. You basically want to put this code in where it can be executed when they try to move on with the program. For example, if you were gathering information to submit to a database and that field could not be empty or null then when the user clicks on the Submit To Database button you would run the code you have and raise the error and exit the function before you run any of the remaining code that needs to be performed. You might even shoot the focus back to the field in question.
If txtCustomer.Text = "" Then
Message = "Please fill in the Customer ID Number"
MsgBox Message, vbOKOnly + vbInformation, "ERROR"
txtCustomer.SetFocus
Exit Function 'or Sub depending on what you are doing
End If
well, since after teh meaasge box is displayed, the textbox loses focus, so theis is what you can do:
dim str as string
//in textchange event of your textbox:
chkid=textcustomer.text
if chkid="" then
msgbox "Cannot be left blank",vbok+vbinformation,"ERROR"
//insert the following
text1.setfocus //this will set the focus back on the
//textbox till the if condition is false.
end if
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.