Move code from button to field instead

stoicy

Registered User.
Local time
Today, 09:26
Joined
Feb 16, 2019
Messages
40
Hello all

I have a Form named frnOrder and that form contain a button which has an event code on click.
I need to delete that button and put its code in the subform "frmOrderDetails" and to let that code take action when the field named "Total" get updated.
 

Attachments

So move the code to a field_Change event. I don't believe those fire if all you do is tab through the field.
 
So move the code to a field_Change event. I don't believe those fire if all you do is tab through the field.
Thank you man

I did on change event but nothing happened!!

Sent from my SM-N900V using Tapatalk
 
I can't look at the sample right now, but if Total is a calculated field or control its update events don't fire when the value changes. You'd need code in the after update events of the controls involved in the calculation.
 
I can't look at the sample right now, but if Total is a calculated field or control its update events don't fire when the value changes. You'd need code in the after update events of the controls involved in the calculation.
Thank you for replay

The Total field is a calculated field and I try to put that code on it after update but also nothing change, there is something wrong!

Sent from my SM-N900V using Tapatalk
 
Read my post again. if you have A+B=C, your code needs to be in A and B, not C.
 
The total after event code which in the subform should update multi field in the main form when its value changed after auto calculation.
If you see the database will understand what I mean
Appreacted

Sent from my SM-N900V using Tapatalk
 
I understand. The events for the total field do not fire when the value changes. You can't do it there. You have to use the after update events of [RealReQu] and [UnitPrice], the fields involved in the calculation.
 
I understand. The events for the total field do not fire when the value changes. You can't do it there. You have to use the after update events of [RealReQu] and [UnitPrice], the fields involved in the calculation.
OK I put it in [Unit Price]
But it didnot update the first prodect record line until I record another purchased line.
It means it update one purchased records of two saved record and the total is not correct because it calculated one record only!!

Sent from my SM-N900V using Tapatalk
 
Are you copying the sum textbox in the subform footer? I'd probably use the after update event of the subform, which won't fire until the record is saved.
 
Here is the OP's code on click event from post#1
This will terminate after executing line one.

Code:
Private Sub Command42_Click()
[Forms]![frmOrder]![HeaderTotal] = [Forms]![frmOrder]![frmOrderDetails]![Text22]

Exit Sub


[Forms]![frmOrder]![InvoiceNetTotal] = [Forms]![frmOrder]![HeaderTotal] - [Forms]![frmOrder]![Discount]
Exit Sub


DoCmd.Save acForm, "frmOrder"
End Sub
 
Remove the Exit Sub lines.

Saving calculated data is usually unnecessary and can be dangerous. Saved results can get 'out of sync' with raw data.
 
The Total field is a calculated field and I try to put that code on it after update but also nothing change, there is something wrong!

Let's start with this fact: You cannot update a calculated field; you must update the factors contributing to its calculation. An unbound field can be altered. A bound field can be altered (and will update the underlying dataset if the change is not cancelled). A computed field is neither of those things.
 
The OP has a sub form of Order details. The Total field for each order item is a calculated field. The footer of the sub form has a text box set to equal the sum of all the line Totals. (The sub form is set to DataSheet so this footer control is not visible in normal form view)

The OP has a button in the main Order form which copies the total in the footer to the Total text box in the Main order form which is bound to the Orders table. The requirement is to replace the button with code in the sub form.

The easiest way is to put the following in the sub form's AfterUpdate event but as Paul has noted, the event won't be triggered until after the record is saved, say by moving off the order detail line.
Code:
Me.Parent!HeaderTotal = Me.Text22
 
Are you copying the sum textbox in the subform footer? I'd probably use the after update event of the subform, which won't fire until the record is saved.
Thank you so much this slove it and no need for that button anymore

I really appreacted your help

Sent from my SM-N900V using Tapatalk
 
The OP has a sub form of Order details. The Total field for each order item is a calculated field. The footer of the sub form has a text box set to equal the sum of all the line Totals. (The sub form is set to DataSheet so this footer control is not visible in normal form view)

The OP has a button in the main Order form which copies the total in the footer to the Total text box in the Main order form which is bound to the Orders table. The requirement is to replace the button with code in the sub form.

The easiest way is to put the following in the sub form's AfterUpdate event but as Paul has noted, the event won't be triggered until after the record is saved, say by moving off the order detail line.
Code:
Me.Parent!HeaderTotal = Me.Text22
Thank you Cronk

You are right and I got the code you put

Thank you all

Sent from my SM-N900V using Tapatalk
 

Users who are viewing this thread

Back
Top Bottom