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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I hate subforms

Status
Not open for further replies.

Bigsteve42

Technical User
Nov 12, 2002
13
GB
Have tried everything but can't seem to get this to work

I have a subform with two fields = debits and credits there is two calcualted controls on the subform footer totaling debits and credits (called TotalCredits and TotalDebits. On the main form is a save button. Since the debits and credits must balance the save button should not be enabled until the two footer controls are equal. I have written the following code:

If Me![TotalDebits] = Me![TotalCredits] Then
Forms!FrmNtmain!Save.Enabled = True
Else: Forms!FrmNtmain!Save.Enabled = False
Endif

When I try this in the AfterUpdate or Exit event it only works after these events have taken place on the next line of the subform. I think the problem is that by the time the total controls are updated the AfterUpdate or Exit events of the Debit and Credit controls have already passed. Could anyone please offer a suggestion? Is it possible to do a loop that would work?

Thanks



 
Not sure where you AfterUpdate event occurs. Is it on the controls or form? I believe it should be on the form. Since the form footer values are based on the totals of all of the records, then it will not be updated until the current record is saved. Therefore, your check needs to go in the AfterUpdate event of the subform.
 
...and additionally I would do a Me.Recalc on the subform before checking the values. But also in the AfterUpdate event of the subform.

And a simpler way (just one line) to enable/disable the button:

Parent("Save").Enabled = Not Sgn(Me("TotalDebits") - Me("TotalCredits"))

I assumed the button was on the main form.

You're going to love subforms [lol]
[pipe]
Daniel Vlas
Systems Consultant
danvlas@yahoo.com
 
Thanks for that guys. Will give that a go. Daniel not sure how the Me.Recalc works could you explain a bit more please.

Cheers

Steve
 
Me.Recalc forces all calculated controls on the form to be recalculated.

Cheers
[pipe]
Daniel Vlas
Systems Consultant
danvlas@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top