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!

Problem With Field Validation Rule In DBC With Forms 1

Status
Not open for further replies.

lr145

Programmer
May 21, 2008
11
I am using Visual Foxpro 6.0 and I have set up a field rule in the database container to prevent the user from entering a future date. I have a form button and with 4 grids. The date field I am validating is in one of the grids. As long as I am in the current grid, the field rule in the dbc works if I enter an invalid date. However, when I try to change the focus to another grid or button, I get the error message. Then my focus is changed to the next object, allowing the incorrect value in the grid. When I try to then close the form I will get a program error.

The database tables are not buffered. Is there anyway I can correct this problem?
 
Sure,
Check ERROR event of your form and intercept the error there. When you get that error just setfocus to the grid.
Better way, use buffered tables and validate ALL in your "Save" routine.

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
Microsoft MVP VFP
 
lr145,

You say that your tables are not buffered. Using DBC-based field validation rules really work best when used alongside buffering.

When you have buffering enabled, you use TABLEUPDATE() to commit the changes. TABLEUPDATE() returns .F. if there is a violation of any of the DBC-based rules (including validation rules, but also things like unique index violations, and also multi-user violations). At that point, you can call AERROR() to give you all the details you need about the error, and you can then decide what action to take.

In my opinion, this is better than leaving it to an error-handler to deal with the situation, for two reasons. First, all the code is in one place -- in the routine that handles the saving of your data. Second, you have full control over the timing of the timing of the process.

That said, Borislav's suggestion of using the form's Error event is a good one; it's just a matter of personal preference.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top