views:

23

answers:

1

I have a field (Total) that has a computed value.

This is the control source: =[FrmSupplierQuote].[Form].[TotalSupplierCost]

This field is updating just fine when the subform is updated

When this field updates I wish to execute the subroutine that updates the field FinalPrice:

Public Sub Update_FinalPrice()
   Me.FinalPrice = Round((Me.Total * (1 + Me.Markup)), 2) 
End Sub

I've tried the events On Change, After Update and On Dirty with no luck. I'm wondering if I've taken the correct approach here and I'm open to suggestions as to how to make this work. I was wondering if I should be driving it from the subForm. I have another form like this that has two subForms.

+1  A: 

You should be clearer in your question as to where the input goes, but presuming the input goes in the subform, then:

  1. The parent form will never after update or change or be dirty as it is the subform that gets dirty, changes and updates.

  2. In the subform's relevant event (I am not sure how you compute the parents "Me.Total", so its not clear which event to use) you can call the Update_FinalPrice sub in the parent form.

  3. This design is nice, because the parent form doesn't need to know the nature of the subform it holds. All it has to do is expose a public Sub that does the work. The onus is then on the subforms to call this sub using their Parent property.

  4. I would write an Update_All method in the parent form and the subform just calls this for all purposes. It might take a bit of refactoring, but you would end up with a simpler app. Otherwise you will be faffing around with any number of combinations of when to calculate the total, when to calculate the final price, etc, etc. Note the maintenance, not development, is the highest cost of software. If badly designed, a lot of that cost should be yours: it is not the client's fault that you got it wrong.

awrigley
Thanks for that, you ckarified what I thought in point 1/ about the events.
MikeAinOz
Retype: Thanks for that, you clarified what I thought in point 1/ about the events. For point 2/ Me.Total is a field on the parent form that is not on the underlying table hence I use =[FrmSupplierQuote].[Form].[TotalSupplierCost] to update it, I'd like to know what event causes this it look like 'Dirty' on the subform. I'll do a call 'up' from the subform to resolve my issues. Please note that I am more than aware of maintenance issues, my problem is that I am iteratively developing with the customer, so the design is fluid
MikeAinOz
I know the iterative feeling. Had it today in fact with a website... Just checking really, as VBA doesn't really encourage Patterns and Practices like more modern languages do. You just have to try and think that way
awrigley
How do I call 'up'? Tried Private Sub Form_AfterUpdate() Dim parentForm As Access.Form Set parentForm = Me.Parent Call parentForm.UpdateFinalPriceEnd Sub
MikeAinOz
Got run time error 2465
MikeAinOz
Don't worry, fixed the spelling error! and called using Me.Parent.Update_FinalPrice , thanks for your help. I think I've been spoilt using modern languages, used to carry it all in my head when I used a pencil!
MikeAinOz