home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / DATABASE / PDXCOED1.ZIP / PDXCOED1.SC
Text File  |  1989-11-20  |  4KB  |  100 lines

  1. ;;when dealing with multitable forms in Paradox,
  2. ;;I like to use the Data Entry Toolkit and force
  3. ;;my user into the first key field on the form,
  4. ;;and test for key violations every time a field
  5. ;;is ready to be departed; when you have a table with
  6. ;;many fields, it is better to know that you are duplicating
  7. ;;a record right from the start, instead of when you are
  8. ;;done with the record and want to post it
  9. ;;since it is usually worth the time to write Procedures
  10. ;;in CoEdit mode ( CoEdit is very handy even if you are not
  11. ;;on a LAN ), but key violations can be tricky when dealing
  12. ;;with multitable forms, this procedure has been worked out;
  13. ;;if should be called whenever you are ready to depart a
  14. ;;key field
  15.  
  16. ;;for example:
  17. ;;   If not TestAnyTableRecForError53()
  18. ;;      then return
  19. ;;   Endif
  20. ;;this procedure does not manipulate the canvas, but it
  21. ;;does toggle TkAccept False if necessary
  22.  
  23. ;;it took awhile to test through all the Errorcodes
  24. ;;and situations to get the procedure this small,
  25. ;;but I know it will save you a lot of time if you use
  26. ;;it. Sprinkle calls to this proc throughout your
  27. ;;application, and you will make life much easier
  28. ;;for your data entry people!
  29. ;;Note: This procedure only tests for tables with up to 2
  30. ;;key fields; if you are working with more keys,
  31. ;;you will have to add more conditions
  32. ;; to the Else + NKeyFields() area , below,
  33. ;;and Locate on as many array "rec" elements as necessary
  34.  
  35.  
  36.  
  37. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  38.  
  39. ;;Let me know if this procedure has been helpful. I need the
  40. ;;encouragement and all of us who do PAL programming will benefit
  41. ;;from sharing some of our experiences. Thanks..
  42.  
  43. ;;;;David N. Thor
  44. ;;;;1474 Greenwood Terrace
  45. ;;;;Marilla, NY 14102-9709
  46.  
  47. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  48.  
  49.  
  50.  
  51.   Proc TestAnyTableRecForError53()
  52.     private rec,previousfield
  53.     PreviousField=Field()
  54.     LockRecord
  55.     Switch
  56.       Case ErrorCode()=55:CopyToArray rec
  57.         UnLockRecord ;the record was already locked
  58.         ;and will fly away if no keyviolation
  59.         If ErrorCode()=53
  60.           Then UnDo           ;we have taken an existing record
  61.                               ;and changed it to an duplicate key
  62.           TkAccept=False      ;so we have to Undo the change
  63.           Beep
  64.           TkMessage="Changes undone! They conflict with existing record!"
  65.           Return False
  66.         Else ;if the UnlockRecord was successful because of no keyviol
  67.           If NKeyFields(Table())=1
  68.              then Locate rec[2]
  69.           Endif
  70.           If NKeyFields(Table())=2
  71.              then Locate rec[2],rec[3]
  72.           Endif
  73.           LockRecord ;record found locked, left locked
  74.           MoveTo Field PreviousField
  75.           Return True
  76.         EndIf
  77.       Case ErrorCode()=53: ;if this was a new record, and
  78.                            ;we already have created a conflict
  79.               beep
  80.         If LinkType()="None" ;if we are in master table
  81.            Then Undo         ;keylookup has no meaning for linked
  82.                              ;master records - we must undo record instead
  83.              TkMessage="New record undone - record already exists!"
  84.            Else KeyLookup
  85.                 LockRecord  ;if this is a detail, we may use keylookup to goto existing
  86.                 TkMessage="Existing record shown!"
  87.                 NewField() ;we will update field otherwise Dowait will think we changed it
  88.         Endif
  89.         TkAccept=False
  90.         UnLockRecord ;found unlocked, left unlocked
  91.         Return False
  92.     EndSwitch
  93.     UnLockRecord
  94.     MoveTo Field PreviousField
  95.    Return True
  96.   EndProc
  97.   WriteLib "???????" TestAnyTableRecForError53
  98.   Release Procs TestAnyTableRecForError53
  99.  
  100.