开发者

Event needed on computed field

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:

  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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜