Log in

View Full Version : Solved: Updating Text Boxes



icthus123
08-15-2007, 08:44 AM
I'm just trying to use a simple public sub.


Public Sub FindTotal()

tbTotal.Value = (tbDFC.Value + tbLCVAP.Value + tbOther.Value)
tbVAT.Value = (tbDFCVAT.Value + tbLCVAPVAT.Value + tbOtherVAT.Value)

End Sub


This is called in the Form_Current Event and on the AfterUpdate events of tbDFC, tbLCVAP, tbOther, tbDFCVAT, tbLCVAPCAT and tbOtherVAT. For some reason it's not updating the values in either tbTotal or tbVAT any ideas why?

icthus123
08-15-2007, 09:02 AM
A slight revision of what I said above. When I go onto a new record they work perfectly! It's only when I'm on the record I've already created that it won't work!

mattj
08-16-2007, 06:22 AM
Have you tried:
Public Sub FindTotal()

Me.tbTotal = (Me.tbDFC + Me.tbLCVAP + Me.tbOther)
Me.tbVAT = (Me.tbDFCVAT + Me.tbLCVAPVAT + Me.tbOtherVAT)

End Sub

You don't need to reference the value, as it is the default property when you reference a control.
On a side note, you just want to display this total - not store it in a table, correct?

Also, if any of the controls are null, you may need to use the NZ function:
Public Sub FindTotal()

Me.tbTotal = (NZ(Me.tbDFC,0) + NZ(Me.tbLCVAP,0) + NZ(Me.tbOther,0))
Me.tbVAT = (NZ(Me.tbDFCVAT,0) + NZ(Me.tbLCVAPVAT,0) + NZ(Me.tbOtherVAT,0))

End Sub

HTH
Matt

icthus123
08-16-2007, 07:19 AM
Thanks a lot Matt that was really helpful!

I'd worked out that the reason it wasn't working was because some of the boxes contained Null values and I got round it by setting a default (even though I didn't really want to!). However, the NZ function gets around this brilliantly! Thanks for drawing my attention to it, I hadn't come across it before!


Have you tried:
On a side note, you just want to display this total - not store it in a table, correct?

That is correct! Thanks a lot!

mattj
08-16-2007, 07:22 AM
Glad I could help!