home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of Shareware - Software Farm 2
/
wosw_2.zip
/
wosw_2
/
DATABASE
/
PDXCOED1.ZIP
/
PDXCOED1.SC
Wrap
Text File
|
1989-11-20
|
4KB
|
100 lines
;;when dealing with multitable forms in Paradox,
;;I like to use the Data Entry Toolkit and force
;;my user into the first key field on the form,
;;and test for key violations every time a field
;;is ready to be departed; when you have a table with
;;many fields, it is better to know that you are duplicating
;;a record right from the start, instead of when you are
;;done with the record and want to post it
;;since it is usually worth the time to write Procedures
;;in CoEdit mode ( CoEdit is very handy even if you are not
;;on a LAN ), but key violations can be tricky when dealing
;;with multitable forms, this procedure has been worked out;
;;if should be called whenever you are ready to depart a
;;key field
;;for example:
;; If not TestAnyTableRecForError53()
;; then return
;; Endif
;;this procedure does not manipulate the canvas, but it
;;does toggle TkAccept False if necessary
;;it took awhile to test through all the Errorcodes
;;and situations to get the procedure this small,
;;but I know it will save you a lot of time if you use
;;it. Sprinkle calls to this proc throughout your
;;application, and you will make life much easier
;;for your data entry people!
;;Note: This procedure only tests for tables with up to 2
;;key fields; if you are working with more keys,
;;you will have to add more conditions
;; to the Else + NKeyFields() area , below,
;;and Locate on as many array "rec" elements as necessary
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Let me know if this procedure has been helpful. I need the
;;encouragement and all of us who do PAL programming will benefit
;;from sharing some of our experiences. Thanks..
;;;;David N. Thor
;;;;1474 Greenwood Terrace
;;;;Marilla, NY 14102-9709
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Proc TestAnyTableRecForError53()
private rec,previousfield
PreviousField=Field()
LockRecord
Switch
Case ErrorCode()=55:CopyToArray rec
UnLockRecord ;the record was already locked
;and will fly away if no keyviolation
If ErrorCode()=53
Then UnDo ;we have taken an existing record
;and changed it to an duplicate key
TkAccept=False ;so we have to Undo the change
Beep
TkMessage="Changes undone! They conflict with existing record!"
Return False
Else ;if the UnlockRecord was successful because of no keyviol
If NKeyFields(Table())=1
then Locate rec[2]
Endif
If NKeyFields(Table())=2
then Locate rec[2],rec[3]
Endif
LockRecord ;record found locked, left locked
MoveTo Field PreviousField
Return True
EndIf
Case ErrorCode()=53: ;if this was a new record, and
;we already have created a conflict
beep
If LinkType()="None" ;if we are in master table
Then Undo ;keylookup has no meaning for linked
;master records - we must undo record instead
TkMessage="New record undone - record already exists!"
Else KeyLookup
LockRecord ;if this is a detail, we may use keylookup to goto existing
TkMessage="Existing record shown!"
NewField() ;we will update field otherwise Dowait will think we changed it
Endif
TkAccept=False
UnLockRecord ;found unlocked, left unlocked
Return False
EndSwitch
UnLockRecord
MoveTo Field PreviousField
Return True
EndProc
WriteLib "???????" TestAnyTableRecForError53
Release Procs TestAnyTableRecForError53