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.
You should be clearer in your question as to where the input goes, but presuming the input goes in the subform, then:
The parent form will never after update or change or be dirty as it is the subform that gets dirty, changes and updates.
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.
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.
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.
精彩评论