justinwu

The way of lock or unlock record or field

Discussion created by justinwu on Mar 26, 2018
Latest reply on Mar 28, 2018 by philmodjunk

I try many way for lock field/record but in vain until the I visit HomeBase Software (https://hbase.net/2014/02/14/record-and-field-locking-strategies/). Many thanks to Douglas Alder!!!

I modified the method suggested by Douglas Alder.

I like to share it. I hope this might help anyone who want to lock record or field.

 

Suppose I had a solution table with A,B,C,D 4 fields and I want to lock A,B,C field (not allow modify record) or entire record (not allow delete record).

1 put a new field in table called Lock Record, and a Value List named Lock list, containing Lock and unLock.

2 put Lock Record in layout, and set the control style to check box and value from Lock list. Adjust the length of Lock Record Field to let only Lock presented in browse mode.  (Not allow unLock presented in browse mode. Unlike Radio button set, although check box set is not unique but user can check it in box off and on in browse mode.)

3 In Database, enter “Lock Record≠"Lock”  in A,B,C field options>Validation>Validation by calculation. And enter the “The record can not be deleted because it is locked.” In Display custom message if validation falls.

4 write a script, Lock Field:

  Allow User Abort [off]

   Set Error Capture [On]

       If [ solution::Lock Record=Lock”]

 

     # let only one first icon OK present.

        Show Custom Dialog [“This filed is locked and can not be modified.”]

        Set Error Capture [On]

 

      If [Get(lastMessageChoice)=1]

        Revert Record/Request [with dialog: off]

        Set Error Capture [On]

        Set Field [solution::Lock Record=Lock

      If [Get(lastMessageChoice)=2]

        Revert Record/Request [with dialog: off]

         Set Field [solution::Lock Record=Lock”]

         Set Error Capture [On]

    End If

End If

5 Set this Lock Field script to Script Trigger in OnObjectModify for A, B, C field in layout mode.

6 If try to use icon to control lock function. Copy the lock and unlock icon in any internet. Arrange both icon to the same size and paste both to layout mode. Set lock icon to hide in the layout with script “solution::Lock Record≠"Lock”. Arrange the unlock icon to just above the lock icon.

 

Any comment will be appreciated.

Thanks for watch my method. I’m still a new comer in FileMaker.

Outcomes