Field Rule Record Events
Description
When defining field rules for a table, there are two types of field rule events to which a script can be attached: Field events and Record events.
CanChangeRecord
Before entering Change mode.
changeRecord>onchangeRecord
After entering Change mode.
CanDeleteRecord
Before deleting a record.
OnDeleteRecord
After deleting a record.
CanEnterRecord
Before moving to the new record.
OnEnterRecord
After moving to the new record
CanMarkRecord
Before marking a record.
OnMarkRecord
After marking a record.
CanSaveRecord
Before saving a record.
OnSaveRecord
After saving a record.
CanUnmarkRecord
Before unmarking a record.
OnUnmarkRecord
After unmarking a record.
To make a record read-only in certain conditions, add code to the CanChangeRecord event that executes the CANCEL() function if those conditions are true.
The A_DELETING_RECORD Variable - Useful in Change and Save Events
To Alpha Anywhere, changing the value in a field, and deleting a record, are both changes to the current record, and both actions trigger the Change and Save record events. This makes it impossible to distinguish between an effort by the user to change a record, or delete the current record. The reason for this is that a record is "deleted" by changing the value in a special "hidden" field in the record. The A_DELETING_RECORD variable allows you to distinguish between deleting and changing a value in a field. A_DELETING_RECORD is set to .T. during a record delete, and to .F. when the record is being edited. With this variable, you can write scripts that do something when the user makes a change to a field value, but not when they delete the record. For example, the following onchange event script shows how you would use the variable:
if .not. A_DELETING_RECORD then '....perform actions normally associated with a record change end if
How to Tell if a Record is Being Deleted
If you would like a script to run if a record is being deleted, or if you would like to prevent a record deletion, put this code in the CanDeleteRecord event of your form.
if (A_DELETING_RECORD = .T.) then ' ... put your code here ' or if you want to cancel the delete, call CANCEL() end if
See Also