Field Rule Record Events
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.
Before entering Change mode.
After entering Change mode.
Before deleting a record.
After deleting a record.
Before moving to the new record.
After moving to the new record
Before marking a record.
After marking a record.
Before saving a record.
After saving a record.
Before unmarking a record.
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.
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
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