Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Field Level Error Message
Message
From
31/05/2004 11:18:24
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
 
To
25/05/2004 12:09:56
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00906987
Message ID:
00908663
Views:
12
>I set field rule & message for it in table of DBC.
>
>when i browse table and enter values which makes field rule to .F. ,and it
>diplays my given message in DBC design.
>
>It displays messagebox() with my message & its default error. and box title
>contains "Microsoft Visual Foxpro".
>
>how can i change this box TITLE to my given title
>
>Anand

I would suggest a redesign in two areas.

First, you would usually not show the end-user a BROWSE window. A Grid on a form offers you much more flexibility.

Second, I personally dislike validation rules, both at the field-level, and at the record-level. The main reason is that both may get evaluated too early, when you can't control it.

A trigger, on the other hand, gets evaluated only when you try a TableUpdate(). (I am assuming that you use buffering, of course.)

Personally, I do most validation through rules stored in a table. Here is my function, which I call when the user tries to save a record:
FUNCTION RecordValid(tcTableName, llEvaluateAllRules)
	* Record validation.
	* Meant to be invoked from form.valid(tablename).
	* Can also be invoked from other places, for instance, triggers.

	tcTableName = lower(tcTableName)
	llEvaluateAllRules = .T.  && Override second parameter.

	* save and change settings
	local lnOldAlias, lcOldExact
	lnOldAlias = select()
	lcOldExact = set("exact")
	set exact off

	* open validation table
	if used("validation")
		select validation
	else
		select 0
		use validation again
	endif
	set order to "mainorder"

	* evaluate all errors defined in rules table
	local lcErrorText, llError
	lcErrorText = ""
	tcTableName = padr(tcTableName, len(Table))
	seek tcTableName
	scan while table = tcTableName
		if Level = "I" && Ignore
			loop
		endif
		select (lnOldAlias)
		if not evaluate(validation.rule)
			lcErrorText = lcErrorText + iif(Validation.Level = "W", "Advertencia: ", "Error: ") + Validation.Spanish
			if not Validation.Level = "W"
				llError = .T.
			endif
			if llEvaluateAllRules
				lcErrorText = lcErrorText + chr(13)
			else
				exit
			endif
		endif
		select validation
	endscan

	* show error message
	if not empty(lcErrorText)
		MessageBox(iif(llError, "No se pudo guardar:", "Advertencia al guardar:") + chr(13) + chr(13);
			+ lcErrorText + iif(llError, "", chr(13) + "Se guardaron los cambios."),;
			16, iif(llError, "Error al guardar", "Advertencia al guardar"))
		*MessageBox(iif(llError, "Can't save:", "Warning on save:") + chr(13) + chr(13);
		*	+ lcErrorText + iif(llError, "", chr(13) + "Changes saved."),;
		*	16, iif(llError, "Error on save", "Warning on save"))
	endif

	* restore environment and return success status
	use in validation
	select (lnOldAlias)
	set exact &lcOldExact
	return not llError
ENDFUNC
And this is the corresponding table structure:
Field  Field Name      Type                Width    Dec   Index   Collate Nulls
    1  TABLE           Character              30            Asc   Machine    No
    2  ORDER           Integer                 4            Asc   Machine    No
    3  RULE            Memo                    4                             No
    4  SPANISH         Memo                    4                             No
    5  COMMENTS        Memo                    4                             No
    6  WARNING         Logical                 1                             No
    7  LEVEL           Character               1                             No
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform