Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Field rounding in Access 2007

Posted on 2013-02-04
8
Medium Priority
?
504 Views
Last Modified: 2013-02-04
I have a formula that runs when the user clicks on a certain field on a form in Access 2007. I have the field set in the table as decimal, fixed, 2 decimal places. I have it set the same way in the form. This works fine if I enter the number but how do I fix this field that is connected to the formula. It keeps rounding to the nearest whole number and I need it to round out 2 decimal places.

I have also tried field = round(2,(field1 - field2)) and that gives me a debug error.
0
Comment
Question by:MRG_AL
  • 3
  • 3
  • 2
8 Comments
 
LVL 66

Expert Comment

by:Jim Horn
ID: 38851643
You have the parameters switched around...

field = round((field1 - field2),2)

Also, you'll want to throw in Nz to handle any NULLS

field = round((Nz(Me.field1,0) - Nz(field2,0)),2)
0
 

Author Comment

by:MRG_AL
ID: 38851869
It is still rounding but is providing two zeros after the decimal point.

The round equation your provided did work in that it didn't give me an error but I can't get it to calculate out two decimal places still.
0
 
LVL 49

Expert Comment

by:Dale Fye
ID: 38851886
My guess is that you have the field in the underlying table defined as an integer.
0
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 

Author Comment

by:MRG_AL
ID: 38851929
It is set up as a decimal on the table. I have tried double, long integer, and decimal. But I have it as Decimal, 2, fixed

That is what I don't understand. I can type in 2 digits after the decimal on a different field but this one runs through the equation and gives me two zeros everytime?!?!
0
 
LVL 66

Accepted Solution

by:
Jim Horn earned 2000 total points
ID: 38851930
fyed would be correct if field1 and field2 are integer values.  It's also possible that something else is either reading it in as an integer, or the form properties are such that it's displaying as an integer.

>It is still rounding but is providing two zeros after the decimal point.
Try rounding separately.

field = Round(Nz(Me.field1,0),2) - Round(Nz(field2,0),2)
0
 

Author Closing Comment

by:MRG_AL
ID: 38852037
It was the Scale on the table. The scale has to be set to 2 and I only had the decimal places set to 2.

Thank you for all your help and advice. The formula works perfect with the rounding now that I have the ,2 at the end of the formula
0
 
LVL 49

Expert Comment

by:Dale Fye
ID: 38852098
So, how does the solution you accepted relate to the scale on the table?

Actually, Access doesn't even have a "scale" property for numeric fields, what system is your backend in?
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 38852409
Thanks for the grade, although if this were a SQL Server linked table, with a scale of 0 as you say, then fyed should receive at least partial credit.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

876 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