Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Abort an Insert 1

Status
Not open for further replies.

wchestnut

Programmer
Aug 9, 2010
79
US
Howdy, again! I know... it's been too long (haha).

How can you abort an Insert procedure without it saving a new record? I have a form with an OK button. On the button, I have source code in an "Control Event Handling, before generated code - Accepted" Embed. In it, there is a condition where if it's not met, it needs to either abort the Insert procedure entirely or return the user back to the form without Inserting a blank or a copy of an existing record. This is what I have so far:

IF LocalRequest = InsertRecord
IF SLSPROSP:ContactID = 0 AND SLSPROSP:CompanyCode = ''
MESSAGE('Record not added: A Company or Contact is required.','INSERT ABORTED')

! DO SyncWindow
! LocalResponse = RequestCancelled
! VCRRequest = VCRNone
! POST(Event:CloseWindow)

! BREAK

! RETURN

! OriginalRequest=''

! Do ProcedureReturn

END
END

I looked through the Module code to see if I can figure out what triggers a clean Cancel. The 4 groups of code after the exclamation point is what I've tried so far. The results return the user to the Browse screen but either it adds a new blank record or a copy of an existing record (what was highlighted in the Browse), depending on which solution I try.
 
Hi!

I am unsure of the correct embed for Legacy, but, you can try ::

POST(EVENT:Accepted, ?Cancel)
CYCLE

Regards
 
Hi!

There is a Legacy embed called: When completed, before writing to disk. This is the embed BEFORE it starts writing to the primary table. This is a much more safer embed since the OK button embed may NOT be executed if the user presses the ESC key and in the warning dialog, he decides to save the changes.

Code:
IF LocalRequest = InsertRecord AND <DoNotSaveConditions>
   LocalResponse = RequestCancelled
   POST(Event:CloseWindow)
   CYCLE  ! Important to prevent any further processing.
END

Regards
 
Actually, CYCLE alone works even better! After a custom popup MESSAGE, it returns the user back to the form allowing them to make corrections. Thanks, again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top