Normal Topic forbid form exit if parent not complete (Read 4383 times)
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
forbid form exit if parent not complete
Aug 13th, 2009 at 10:03pm
Print Post Print Post  
Hammer, on Jan 19th, 2006 you wrote the following piece of code for Spencer that used a variable to alert the user upon form exit that a value had changed.  I'm wanting to do the same thing, but wish to insure that a parent form (Orders) can't be exited via <esc> key if the user is in the subform (SOLines) at the time.  I have added your code to my parent form in the requisite events, but it doesn't prevent the parent form from being exited, nor a message pops up.  Where am I offtrack?

from Jan 19, 2006 post:

2.0 wil expose all attributes, including the undo value.

Meanwhile, if you want to compare a value to what it originally was when you arrived at the record, use a variable instead of a "shadow field". For example:

Global Code
----------------
stat vShadow as String  

      vShadow = ""


On Form Entry
------------------
vShadow = LEToShadow


On Form Exit
-----------------
If vShadow <> LEToShadow
{
      @MsgBox("You changed the value!", "", "")
}
  

Larry
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: forbid form exit if parent not complete
Reply #1 - Aug 14th, 2009 at 12:50am
Print Post Print Post  
On Form Exit doesn't run when using Escape. We don't run code when you are trying to leave without saving changes. There is a NotifyForm flag to prevent the form from closing and there are functions like @FormWillClose and RunExitProgrammingOnCloseForm(), but it might be tough to get everything in the right place. Some experimentation would be required as to whether it works as you want when placed in the Parent Form or in the Subform.

Why are people not allowed to leave if they are in a subform?
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Re: forbid form exit if parent not complete
Reply #2 - Aug 14th, 2009 at 1:28am
Print Post Print Post  
Sales Order Parent form has an OrderSubmit button that has code that saves the sub and the parent and sends email to us which alerts us to pull up that Sales Order number and print the order so we can process it.  

The client is online to place an order;  he's adding line items (each time he commits another line item, the Parent is saved also); if he forgets to press the OrderSubmit button on the parent form and escapes out of the LineItem subform, though, the code in the OrderSubmit button isn't triggered to send us an alert email.  That's why I'd like to prevent an escape without pressing the OrderSubmit button or the 'DeleteThisOrder and its lineitems' button

I tried NotifyForm(6), but put it in FormExit and as I now just learned, the code didn't run.  Perhaps I should put it in the ClientID:OnElementChange field on the Parent form, and then put NotifyForm(-6) in both OrderSubmit button (in the case of a save) and in the OrderDelete command button (in the case where the client of an aborted order) ?    

Of course, I'm all ears to learn of a more elegant solution  ;)
  

Larry
Back to top
IP Logged
 
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Re: forbid form exit if parent not complete
Reply #3 - Aug 14th, 2009 at 1:59am
Print Post Print Post  
putting NotifyForm(6) in the parent, and then NotifyForm(-6) in OrderSubmit and OrderDelete buttons worked to prevent the form from being exited with the escape key (thank you!).  But I would love for the mistried <esc> key to pop a MsgBox instructing the user to, in effect, fish or cut bait.  I'll dig a little.
  

Larry
Back to top
IP Logged
 
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Re: forbid form exit if parent not complete
Reply #4 - Aug 16th, 2009 at 5:34pm
Print Post Print Post  
NotifyForm(6) in the Parent also included the subform, but if the subform was toggled into tableview, it would no longer obey its NotifyForm(6) inherited instruction from the Parent.   Putting NotifyForm(6) in the subform::FormReveal fixed that.

Am I correct in concluding that this is also generally true - that subforms lose their inherited instructions if they are toggled into and out of tableview?
  

Larry
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: forbid form exit if parent not complete
Reply #5 - Aug 17th, 2009 at 2:07pm
Print Post Print Post  
It depends on the "instruction", though, in general I wouldn't assume any inheritance from form to form or form to table. It is much better to be explicit and tell each form exactly how you want it to behave. Some "instructions" can't help but be inherited, others will be ignored as inappropriate, some will be interpreted to be appropriate for a form or table - and so, act differently.

In general, I believe that you should reconsider designing around the idea that people can't leave/cancel a form. They will always be able to do so. If you obstruct the easy paths (hitting Escape), they will take the less desirable paths (killing the process). We cannot entirely eliminate their ability to whack any running program, including Sesame. If you give them no alternative path, you will have to deal with increasingly extreme situations.

If your programming is causing a "commit" of any kind before the user has submitted a final top-level form commit, you should either find some way to hold off until that user is certainly not canceling, or find some way to "roll back" the lower level information. You might consider including a flag in that information that indicates that it pending a higher level commitment on the part of that user. Set that flag for all subrecords after the parent record has been committed. Otherwise, check for clear flags occasionally and eliminate those subrecords, either be removing them from a result set in use, deleting them, or ignoring them in calculations.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Re: forbid form exit if parent not complete
Reply #6 - Aug 17th, 2009 at 10:48pm
Print Post Print Post  
Mark,

What you say makes perfect sense.  I'm always butting up against the short ceiling of my knowledge, and how I initially wrote the Sales Order and SOLines programming was to have each line item 'Add' as a 'commit' (an easier task during my learning curve).  I know I should rework the Sales Order - just as you've described - so that the line items are added, but not committed until the Parent is executed, and then each line item is posted through a loop.   My work around in the interim has been a Reversing Entry button that will delete the current line item and roll back any inventory quantity fields affected.

     Your description is much more elegant ... It's just a question of time, energy, and brain limits (not necessarily in that order).  Thanks for the blueprint, though.
  

Larry
Back to top
IP Logged