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!

Code - How do I save a form and close the window using code? 1

Status
Not open for further replies.

emaduddeen

Programmer
Mar 22, 2007
184
US
Hi Everyone,

Can you tell me how to save the data on an update form and close the window just like the the Ok button does using code?

Thanks.
Emad
 
Hi Emad,

Just do a POST(EVENT:Accepted, ?OKButton) if the ?OKButton is the label of the OK button. This is as good as pressing the OK Button.

If you are using your own button and not a template, then a simple

CASE ThisWindow.Request
OF InsertRecord
ACCESS:Table.Insert()
OF ChangeRecord
RELATE:Table.Update()
OF DeleteRecord
RELATE:Table.Delete()
END
POST(EVENT:CloseWindow)

would do.

Regards
 
Hi ShankarJ,

Thanks for the code.

I will use it.

Truly,
Emad
 
Hi ShankarJ,

Here is the code I used. I kind of works. When the close window event if fired, the program displays a dialog asking "Are you sure you want to cancel". It seems that the program trys to insert the row twice. The forms was created by the template.

Thanks,
Emad

Code:
! Calculate discount if sell price is < 0.
!-----------------------------------------
If TranDet:SellPrice < 0 |
Then
   TranDet:DiscountPercent = 0 - TranDet:SellPrice
   TranDet:DiscountAmount = 0 - ((TranDet:RegularPrice * TranDet:SellPrice) / 100)
   TranDet:SellPrice = TranDet:RegularPrice - TranDet:DiscountAmount
Else
   TranDet:DiscountPercent = 100 - ((TranDet:SellPrice / TranDet:RegularPrice) * 100)
   TranDet:DiscountAmount = (TranDet:RegularPrice - TranDet:SellPrice)
End

TranDet:LineTotal = TranDet:SellPrice * TranDet:Quantity

Display

Alias ! Temporary allow the enter key to be the enter key not the tab key.

If KeyCode() = TabKey |
Then
   CASE ThisWindow.Request
   OF InsertRecord
      ACCESS:TransactionDetails.Insert()
   OF ChangeRecord
     RELATE:TransactionDetails.Update()
   END

   POST(EVENT:CloseWindow)
End
 
Hi Emad,

If it is a FORM template, all you need to do is a POST(EVENT:Accepted, ?OK). The template code will do the rest.

The suggestion use the Insert(), Update() & Delete() methods were ONLY if it was a generic Window procedure.

So,
Code:
If TranDet:SellPrice < 0 |
Then
   TranDet:DiscountPercent = 0 - TranDet:SellPrice
   TranDet:DiscountAmount = 0 - ((TranDet:RegularPrice * TranDet:SellPrice) / 100)
   TranDet:SellPrice = TranDet:RegularPrice - TranDet:DiscountAmount
Else
   TranDet:DiscountPercent = 100 - ((TranDet:SellPrice / TranDet:RegularPrice) * 100)
   TranDet:DiscountAmount = (TranDet:RegularPrice - TranDet:SellPrice)
End

TranDet:LineTotal = TranDet:SellPrice * TranDet:Quantity

Display()

UPDATE()

POST(EVENT:Accepted, ?OK)
should work.

Regards

 
Hi ShankarJ,

I tried the code, but the program gets locked into some kind of loop so the Insert(), Update() & Delete() methods look like the way to go for this form. The only thing I don't know is why it does that "Cancel" dialog.

Truly,
Emad
 
I wonder if you're running this code inside of an EVENT:ACCEPTED portion of the logic.

In which case, surround it with:

IF 0{prop:AcceptedAll}=FALSE

If TranDet:SellPrice < 0 |
Then
TranDet:DiscountPercent = 0 - TranDet:SellPrice\

!etc.
!etc.
!etc.

POST(EVENT:Accepted, ?OK)

END

HTH,
Mark Goldberg
 
Hi Emad,

In which embed are you executing the code? If it is on the Accepted embed of a entry control, there should be no problem. Or, you can call ThisWindow.TakeCompleted() directly (I have not tried that).

To disable the SAVE message do the following :

Code:
ThisWindow.CancelAction = Cancel:Cancel

POST(EVENT:CloseWindow)

If this Form is being called from a Browse, the browse will NOT refresh automatically since you are cancelling from a form. You have to do that manually i.e.

Code:
BRWn.ResetQueue(Reset:Queue).

Regards
 
Hi Everyone,

I am using the code from an "Acepted" embed of an entry control called TranDet:SellPrice.

The form is also called from a Browse.

I will experiment with both of your suggestions tonight.

Thanks.
Emad
 
Hi Emad,

If you want this code to fire always after the TranDet:SellPrice, then set the ?TranDet:SellPrice{PROP:Touched} = True in the EVENT:Selected of ?TranDet:SellPrice. Maybe this will solve your problem and remove the necessity of the KEYCODE() = TabKey check.

Regards
 
Hi ShankarJ,

?TranDet:SellPrice{PROP:Touched} is already in the "Selected" embed because of the calculating code.

I tried ThisWindow.CancelAction = Cancel:Cancel and it worked nice. I did look up CancelAction in the help and found Cancel:Save and also tried that, but I was back to the locking up issue so I kept it at Cancel:Cancel.

Thanks to both you and Mark for the help.

Truly,
Emad
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top