Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Triggers
Message
From
17/09/2002 11:51:05
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Miscellaneous
Thread ID:
00701299
Message ID:
00701318
Views:
19
This message has been marked as a message which has helped to the initial question of the thread.
>Hi everybody,
>
>I want to automatically update a field in a table. If I add a record, I want to put 'A' in ModiType, if I change it, I want to put 'C' and if I delete it, I want to put "D". I tried to use triggers for this, but got can not update cursor message. How can I perform this update automatically?
>
>It's for VFP6.

Nadya,

A trigger cannot update the record that caused it to fire. It can update/delete/insert other records of the same table or any record in another table. (you can keep the status in another table though)

The only possibility left is to change the record in the record validation rule.

You'll have to do some testing

reopen the table and seek
if found()
it's an update
else
it's new record
endif

another method to see wether it's an insert is to test for isnull(oldVal('fieldname')) provided that nulls are not allowed for that field


Watch out for the fields that form the key. They can possibly change ( fieldname and oldval('fieldname'))

Here's how I check whether a field has changed or not.

The RecordValidation also fires when you replace a field with its same value. ( eg repl FieldName with FieldName ). You will have to check whether any field has changed
&& eg: FieldChanged('TheFieldName')

function FieldChanged(FieldName)

	do case
	case isnull(oldval(FieldName)) or Isnull(eval(FieldName))
		return (isnull(oldval(FieldName)) <> Isnull(eval(FieldName)) )
	otherwise
		return (oldval(FieldName) <> eval(FieldName))
	endcase
endfunc
*-------------------------------------------------------------------------
The Field validation does not fire when you delete a record. But is that necessary since you can check for deleted() ?
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform