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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

stop code for form event

Status
Not open for further replies.

shawnwmorris

Programmer
May 4, 2017
36
US
I have a simple form project that will take a value and use that to do some SQL statements. I am trying to check the textbox to make sure there is a value actually present in the textbox after the "go" button is pushed. In the code of for the click event of the button I have some code to execute the SQL statements.

I want to put the check in the code for the button after it is pressed. How do I make the code stop executing? I want nothing to happen if the textbox is not filled in.

I have this:
IF thisform.polNum.Value = ""
MESSAGEBOX("Please enter a Policy number to continue",16,"All done!")
Exit
endif

This creates a nesting error. How do I just stop the code from moving past that point?
 
You can't put EXIT in an IF/ENDIF. What you need is an ELSE.

Something like this:

Code:
IF EMPTY(thisform.polNum.Value)
  * Put your message here
  RETURN
ELSE
  * Excecute your SQL here
ENDIF

The RETURN will exit the code in the button and let the user correct the mistake.

As an added convenience, you could put this immediately after your message:

Code:
THISFORM.polNum.SetFocus

This will make it that little bit easier for the user to edit the textbox.

Note also that I have used EMPTY() rather than testing for an empty string is this will do the job regardless of data types.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike thanks for the help. I am kicking myself for not thinking of the bigger if statement.
 
You're welcome, Shawn. By the way, I should add that the RETURN isn't essential if you have no other code in the relevant method. If you left out the RETURN, you would still only execute the SQL code if the textbox passed its validation text.

Not a big point, but worth keeping in mind.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top