INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Code - How do I save a form and close the window using code?Helpful Member! 

emaduddeen (Programmer) (OP)
8 May 07 6:10
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
Helpful Member!  ShankarJ (Programmer)
8 May 07 9:58
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
emaduddeen (Programmer) (OP)
8 May 07 22:36
Hi ShankarJ,

Thanks for the code.

I will use it.

Truly,
Emad
emaduddeen (Programmer) (OP)
9 May 07 8:05
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
ShankarJ (Programmer)
9 May 07 14:03
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

emaduddeen (Programmer) (OP)
10 May 07 6:53
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
MarkGoldberg (Programmer)
10 May 07 8:29
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
ShankarJ (Programmer)
10 May 07 11:15
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
emaduddeen (Programmer) (OP)
10 May 07 12:49
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
ShankarJ (Programmer)
11 May 07 2:08
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
emaduddeen (Programmer) (OP)
11 May 07 6:33
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

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close