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
13
Medium Priority
?
319 Views
Last Modified: 2012-05-12
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
Comment
Question by:ssmith94015
  • 6
  • 6
13 Comments
 
LVL 75
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

by:AielloJ
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
ID: 36920743

And highly recommended reading:

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

mx
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 75

Accepted Solution

by:
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

by:ssmith94015
ID: 36921155
I think you both have the problem nailed.  Will try suggestions and be back.
0
 
LVL 75
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

by:ssmith94015
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

by:ssmith94015
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

by:ssmith94015
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
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

by:ssmith94015
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
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

by:ssmith94015
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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…

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question