473,386 Members | 1,609 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Problems in calculations in MS Access 2003

Hi all,

I have a problem with some calculations in MS Access 2003. I have 3
fields (Qty, Price and VolumeUSD) in a form and the following formula:
VolumeUSD = Qty * Price.

Qty and VolumeUSD are formated as "Standard" and Price as "General
Number".

Example: Qty = 4,400 ; Price = 39.1602

When all 3 fields are "Single", VolumeUSD = 172,308.90 (wrong)!
BUT, when all 3 fields "Double", VolumeUSD = 172,308.88 (correct)

I have much more situations where I get errors in calculations if I use
the variables as "Single".

CAN SOMEONE EXPLAIN ME THIS ?!

In the Database I have about 4000 records! Until now the only way I can
imagine to fix this problem is to change in the Table Design all three
variables from Single to Double, but if I do this the Price will change
to 39,1601093458574357 instead of 39,1602! This means that I will have
to input again the Price for each of the 4000 records!!! This will take
a lot of time!

THERE'S ANY OTHER WAY TO FIX THIS PROBLEM IN THE DATABASE IN A MUCH
FASTER WAY ?

Urgent!!!

Thanks, Miguel Teixeira.

Nov 13 '05 #1
6 3818
With many of the reports I created in Access there is a problem of
rounding off. But I can live with that! Its usually no more then a
dollar difference. Reports that have large Sums I declare a variable as
variant. Then use either the Format Currency Function or Format
Function, then set total sum how many decimal places. Have to be
consistence with variables. You can use module function for every
calculation needed. That way all the changes also will be consistence.
I don't think I would use Single for this type of calculation. Even
though the Qty I would probadly use an integer. Hope this help you.
Dim varSum As Variant

varSum = Format(varSum, "$##.#0")

'FormatCurrency Function

varSum = FormatCurrency(varSum, 2, vbTrue, vbTrue, vbUseDefault)

'FormatCurrency(Expression[,NumDigitsAfterDecimal [,IncludeLeadingDigit
,UseParensForNegativeNumbers [,GroupDigits]]]])
Also make sure from the table properites, textbox propertes on forms
and query properties have the same datatype also, its good ideal to
check. I don't think you have to reenter the data to change how the
data is view, you should be able to change for instance from a number
to currency.

loringdo

Nov 13 '05 #2
I forgot one more thing.

Public sub pViewTheAns()

Dim mQty as integer
Dim mVol as variant
Dim mPrice as Currency

mQty = 100
mPrice = 45.36

mVol = FormatCurrency(mQty * mPrice,2, vbTrue, vbTrue, vbUseDefault)

Debug.Print mVol

End Sub

Nov 13 '05 #3
I forgot one more thing.

Public sub pViewTheAns()

Dim mQty as integer
Dim mVol as variant
Dim mPrice as Currency

mQty = 100
mPrice = 45.36

mVol = FormatCurrency(mQty * mPrice,2, vbTrue, vbTrue, vbUseDefault)

Debug.Print mVol

End Sub

Nov 13 '05 #4
I forgot one more thing.

Public sub pViewTheAns()

Dim mQty as integer
Dim mVol as variant
Dim mPrice as Currency

mQty = 100
mPrice = 45.36

mVol = FormatCurrency(mQty * mPrice,2, vbTrue, vbTrue, vbUseDefault)

Debug.Print mVol

End Sub

Nov 13 '05 #5
Thanks a lot! Extremely helpful.

Nov 13 '05 #6
On 21 Oct 2005 08:57:37 -0700, mi*******@gmail.com wrote:

[snip]
Qty and VolumeUSD are formated as "Standard" and Price as "General
Number".

Example: Qty = 4,400 ; Price = 39.1602

When all 3 fields are "Single", VolumeUSD = 172,308.90 (wrong)!
BUT, when all 3 fields "Double", VolumeUSD = 172,308.88 (correct)

I have much more situations where I get errors in calculations if I use
the variables as "Single".

CAN SOMEONE EXPLAIN ME THIS ?!


Yes. You're using the wrong data type. "Format" has to do with how
values look, not with what the values are. You can format '1.23456789'
to look like '1.23', but that doesn't change its value.

You need to use the Currency or Decimal data type for [Price] and
[VolumeUSD]. If you need fractional quantities, use Currency or
Decimal for [Qty]. Otherwise, use Integer or Long Integer. Read
Access Help first.

You probably also need to round the right value to the right number of
decimal places at the right time. "Right value", "right number of
decimal places", and "right time" are application-dependent.

Don't change the data type of your existing columns. Add new columns,
get the right values into the new columns, then delete the old ones and
rename the new ones.

--
Mike Sherrill
Information Management Systems

Nov 13 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: CAFxX | last post by:
i'm writing a program that executes some calculations on a bitmap loaded in memory. these calculation ends up with pixel wth values far over 255, but i need them to be between 0 and 255 since i...
3
by: carverk | last post by:
Hello All I'm in the middle of moving a MS Access DB to a MySql backend. I have figured out about 90% of the problems I have faced, execpt for this one. I have 3 Queries, which pull records...
7
by: Wayne Aprato | last post by:
I have several Access 2003 mde databases. When I try to open them in Access 2002 I get the following error: "The Visual Basic for Applications project in the database is corrupt." ...
0
by: David G. | last post by:
The keyboard type ahead buffer does not seem to work in Access 2003 in certain situations. We would like some help with this. Here are the details. We have a large program that was developed...
10
by: BBFrost | last post by:
We just recently moved one of our major c# apps from VS Net 2002 to VS Net 2003. At first things were looking ok, now problems are starting to appear. So far ... (1) ...
4
by: William Cruz | last post by:
Ok, here is my situation. I have created a class called “Calculations” in the main form of my project, I declare this class as “Dim Calcs as New Calculations” and everything is fine and dandy, but...
3
by: google | last post by:
I'm developing an application for use within my company in Access 2003. I'm new to '03, the application I did for my former employer was in '97. The two applications have similar functionality...
2
by: Xeijin | last post by:
URGENT I have an assignment to hand in tomorrow, I need to know how to perform numeric calculations in access, I dont know very much about databases so consider this a beginner's query! Well...
18
by: TORQUE | last post by:
Hi, Im wondering if anyone can help me with a problem. I have a form with more than 50 unbound fields. Some of the fields will be blank from time to time. This seems to be where im having...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.