Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
Solved

# ACCESS 2003 not recognizing two numbers as equal on a form

Posted on 2011-10-05
Medium Priority
319 Views
I have a form that the users inputs totals, then in another section they input details.  There is a check that the total amount should equal the sum of the details.  Most of the time it work,s but everynow and then (like now!) while the numers look the same, internally they are slighly different, so the VBA will throw an error and the user gets a message box his numbers don't match, when visually they do.  What would be the best approach to tell ACCESS that these numbers really are the same?  Right now I have 67,637.60 in two fields, but internally they have a slight difference.
0
Question by:ssmith94015
• 6
• 6

LVL 75

Expert Comment

ID: 36920589
By slightly different I suppose you mean several decimal points out?

You might try something like

If Round(YourNumber1, 2) = Round(YourNamber2, 2) Then
.....
0

LVL 13

Expert Comment

ID: 36920700
ssmith94015:

It appears you are experiencing classic MS-Access rounding errors.  Many times the math is done in floating point, producing numbers 5 and 6 places out.  Try the ROUND function.  A reference is available at:

http://www.techonthenet.com/access/functions/numeric/round.php

regards,

AielloJ
0

LVL 75

Expert Comment

ID: 36920743

http://www.xbeat.net/vbspeed/c_Round.htm

mx
0

LVL 75

Accepted Solution

DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 2000 total points
ID: 36920813
This might be a better test:

If Left(YourNum1,InStr(1,YourNum1,".")+2) = Left(YourNum2,InStr(1,YourNum2,".")+2) Then

....

This caps it off at 2 dec pts.

mx
0

Author Comment

ID: 36921155
I think you both have the problem nailed.  Will try suggestions and be back.
0

LVL 75

Expert Comment

ID: 36921196
I'm not sure Round is going to be 100% fool proof.  However, limiting the value to two dec pts should always work.  Round *could* possibly still make the numbers different.

mx
0

Author Comment

ID: 36921251
Mx, would you suggest,then, that

Left(YourNum1,InStr(1,YourNum1,".")+2) = Left(YourNum2,InStr(1,YourNum2,".")+2)

would be a better choice than ROUND?

I read both source articles, thanks for the references.
0

Author Comment

ID: 36921254
I do have the numbers limited to 2 decimal places and they should not be inputting anything with more than that anyway.
0

Author Closing Comment

ID: 36921260
I went with this version as I am concerned about the chance of ROUND not producing the results I want - otherwise the user is stuck with the form open as there would be no way to close it if there is a difference in any of the compared values.
0

LVL 75

Expert Comment

ID: 36921283
"would be a better choice than ROUND?  "
That's what I'm thinking.

"and they should not be inputting anything with more than that anyway."
Right ... but this is happened when summing the results, right?  What are examples of these differences?

mx
0

Author Comment

ID: 36921298
yes, they do input more than they should and what I also found out, they are inputting what they think are 0's in some of the fields and no, they are not really 0.  So, while the display may show only two values, those sneaky, pesky little invisilble decimal values are messing up the calculations.
0

LVL 75

Expert Comment

ID: 36921321
I see.  Although I'm not a big fan of Input Masks, in this case it might make sense ...?

mx
0

Author Comment

ID: 36924282
Just might.  I am going to see how the current change works and may go that route as well if necessary, thanks for the suggestion.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then readingâ€¦
If youâ€™re using QODBC to update QuickBooks data from MicrosoftÂ® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns overâ€¦
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increasedâ€¦
###### Suggested Courses
Course of the Month11 days, 16 hours left to enroll