Lightening


Try to save some code, such as :

If empty(name)

messagebox("Name field cannot be empty.",16," Alert")

return 0

Endif

How can I put the expression in the field validation rule box Unable to find examples in the help.




Re: How to use the field validation rule?

Naomi Nosonovsky


rule:

!empty(Name)

Error:

"Name field cannot be empty"






Re: How to use the field validation rule?

Lightening

thanks. But when I copy and paste your stuff into the rule box. it says "syntax error."




Re: How to use the field validation rule?

Naomi Nosonovsky

Worked for me with my field. Perhaps the problem that NAME is a reserved VFP word Did you just try not empty(MyField) in the rule And the text for error message in the Error



Re: How to use the field validation rule?

Lightening

When you click the OK button, !empty(name) converted automatically to

.NOT. empty(name)

What did you actually put into the message box

"Name cannot be empty"

I tried with quotes or without . none of them works.





Re: How to use the field validation rule?

Naomi Nosonovsky

I put it in double quotes in the designer and it worked (e.g. validation worked immediatelly). Do you want to do it programmatically without validating old records



Re: How to use the field validation rule?

AndyKr

To use a field validation rule interactively you must do the following:

[1] Add the rule as a valid VFP Expression that will return either .T. or .F.

[2] Add the message as a string (you can use single or double quotes, or "[ xxx ]"

[3] Add a default value if necessary (generally I prefer to use a default rather than an error - but it is not always possible)

[4] Save the change and check the box to either Apply rule to existing data, or not.

If you want to do it programmatically you either use the Alter Table command like this:

ALTER TABLE customers ;

ALTER COLUMN name ;

SET CHECK NOT EMPTY(name) ERROR "Name cannot be empty"

or use DBSETPROP() to set the RuleExpression/RuleText properties (this is really for Views/Cursors! )






Re: How to use the field validation rule?

Lightening

Thank you both. I just want to check user's data entry.

At the Table Designer window, when I click the OK button, it shows the message: "Name cannot be empty."

But it did not get saved (you cannot exit the designer window.) unless I removed the rule expression and message content.





Re: How to use the field validation rule?

Naomi Nosonovsky

That's what I meant when I said about NOVALIDATE. You probably have wrong data in your table (empty names) and now you can not pass it. Either fix the data first and then apply your rule or do it programmatically with ALTER TABLE command but add NOVALIDATE at the end.



Re: How to use the field validation rule?

Lightening

Thank you so much. I did find some records that have empty name fields.

I deleted them and it worked perfectly now.





Re: How to use the field validation rule?

Naomi Nosonovsky

Glad it worked. <g>