Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Loop 1

Status
Not open for further replies.

Cimso

Technical User
Sep 25, 2001
22
US
How would I loop this until it was done?

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
 
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


Hope this helps...
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top