[AccessD] Strange results with simple calculation on a form

Gustav Brock gustav at cactus.dk
Thu Mar 18 04:18:43 CST 2004


Hi Bert-Jan

Welcome back.

Unbound textboxes contain text no matter how you format them.
And decimals may not be exact Doubles and indeed not Singles.

If you can accept a maximum of four decimals, use CCur(txtYourTextbox)
to convert to Currency before doing any calculation or comparison.
Else use CDbl() and compare to a max. tolerance of your choice:

  If Abs(dblTotal - dblAmount) < 1E-7 Then
    ' Values are equal.
  End If

/gustav


> Hi all,

> i was forced to unsubscribe a while ago because i couldn't keep up with you
> and all the messages... ;-)

> But today a strange thing happened i had to ask you all about. I didn't do a
> big search on the internet, but searched the accessd archives and didn't
> find it. It maybe is a well known problem, but here it goes.....

> I have an unbound form where users will type amounts. All the txtboxes'
> format are set to "standard" and the decimal places is set to 2. And i check
> on the before_update event of these txtboxes if there are more then 2
> decimals, if so, cancel = true. There is an calculated total control
> (txtTotal) wich has a controlsource like =[txtbox1]+[txtbox2] and so on (in
> total 12 txtboxes)
> These txtboxes are used to 'split up' the amount in another txtbox.
> (txtAmount)

> Before saving i check if txtAmount = txtTotal. When no decimals are used
> there is no problem, if there are only used decimals in 1 txtbox there is no
> problem. But if there are used decimals in more txtboxes access will tell me
> the values are not the same..... although the same values are shown... it
> turns out there is a difference of: 0.00000000000000710542735!!!!!!
> (debug.print told me this!)

> When i use the same 'function' in VBA it works fine with the same
> values....????

> So it is not a real problem, but it IS something strange... wel to me it
> is....

> Thanks in advance.

> Hope to keep up with you this time... ;-)

> Bert-Jan




More information about the AccessD mailing list