INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

stop code for form event

stop code for form event

(OP)
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?

RE: stop code for form event

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

RE: stop code for form event

(OP)
Mike thanks for the help. I am kicking myself for not thinking of the bigger if statement.

RE: stop code for form event

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close