How do i breakdown change into denominations

P

paulkemp39

Hi can anyone help with the following using access 2003.

I am creating a report in access to give to our accounts department that
shows amounts of money to be paid out.
I am trying to work out the breakdown of a value into notes and coins.
e.g. person A made £46.36 so would need 2x£20 1x£5.00 1x£1 1x£0.20 1x£0.10
1x£0.05 and 1x£0.01
person B made ..... etc.
This would then be added up at the end and then a total for each
denomination would also be needed.
Total = 6 x £20.00 3 x £10 4 x £5.00 .... etc.

Many thanks in advance
paulkemp39
 
M

Mr. B

Someone else may have a more elegant way of doing this but here is one way.

Below is a Public function that you can put in a module and then call from
anywhere, passing the amount to be evaluated.

In addition to the variables defined in the function, plese note that at the
end of the function I am assigning the counts to public variables by adding
the new counts to the any existing counts. For this, I have defined the
variable you see at the end as public variables in the module. This will let
the accumumlate values. I tested this by calling the function from a button
on a form. I used code in the OnOpen event of the form to reset the public
variables that will hold the grand totals for each denomination.

Here is the function:

Public Function SetDemonination(Amount As Double)
Dim lngTwenties As Long
Dim lngTwentyAmt As Long
Dim lngTens As Long
Dim lngTensAmt As Long
Dim lngFives As Long
Dim lngFivesAmt As Long
Dim lngOnes As Long
Dim lngTwentyCnts As Long
Dim lngTwentyCntsAmt As Long
Dim lngFiveCnts As Long
Dim lngFiveCntsAmt As Long
Dim lngOneCnts As Long
Dim intDecmlPlc As Integer
Dim intCentsAmt As Integer
'calculate the number of 20's
If Format(Amount, "00") >= 20 Then
lngTwenties = Int(Format(Amount, "00") / 20)
lngTwentyAmt = lngTwenties * 20
End If
'calculate the number of 10's
If Format(Amount - lngTwentyAmt, "00") >= 10 Then
lngTens = Int(Format((Amount - lngTwentyAmt), "00") / 10)
Else
lngTens = 0
End If
lngTensAmt = lngTens * 10
'calculate the number of 5's
If Format(Amount - (lngTwentyAmt + lngTensAmt), "00") >= 5 Then
lngFives = (Amount - (lngTwentyAmt + lngTensAmt)) / 5
Else
lngFives = 0
End If
lngFivesAmt = lngFives * 5
lngOnes = Amount - (lngTwentyAmt + lngTensAmt + lngFivesAmt)

'Look for a decimal place
intDecmlPlc = InStr(Str(Amount), ".")

'Check to see that a decimal place was founc
If intDecmlPlc > 0 Then
'Convert cents
intCentsAmt = Left(Mid(Str(Amount), intDecmlPlc + 1) & "00", 2)
lngTwentyCnts = Int(intCentsAmt / 20)
lngTwentyCntsAmt = lngTwentyCnts * 20
If intCentsAmt - lngTwentyCntsAmt >= 5 Then
'get the Five cent count
lngFiveCnts = Int(intCentsAmt - lngTwentyCntsAmt) / 5
Else
lngFiveCnts = 0
End If
lngFiveCntsAmt = lngFiveCnts * 5
lngOneCnts = intCentsAmt - (lngTwentyCntsAmt + lngFiveCntsAmt)
Else
lngTwentyCnts = 0
lngOneCnts = 0
End If
'assign the counts of each demonination to global variables
lngTotalTwenties = lngTotalTwenties + lngTwenties
lngTotalTens = lngTotalTens + lngTens
lngTotalFives = lngTotalFives + lngFives
lngTotalOnes = lngTotalOnes + lngOnes
lngTotalTwentyCnts = lngTotalTwentyCnts + lngTwentyCnts
lngTotalOneCnts = lngTotalOneCnts + lngOneCnts

Debug.Print lngTotalTwenties & " 20's"
Debug.Print lngTotalTens & " 10's"
Debug.Print lngTotalFives & " 5's"
Debug.Print lngTotalOnes & " 1's"
Debug.Print lngTotalTwentyCnts & " 20 cents"
Debug.Print lngTotalOneCnts & " cents"
End Function

Here are the public variables that I defined in the module:
Public lngTotalTwenties As Long
Public lngTotalTens As Long
Public lngTotalFives As Long
Public lngTotalOnes As Long
Public lngTotalTwentyCnts As Long
Public lngTotalOneCnts As Long

Good luck with your project.





-----
HTH
Mr. B
http://www.askdoctoraccess.com/
Doctor Access Downloads Page:
http://www.askdoctoraccess.com/DownloadPage.htm
 
J

John... Visio MVP

Steve said:
If you need help writing the code, I will do it for you for a small fee.
Contact me if you need help.
These newsgroups are provided by Microsoft for FREE peer to peer support.
There are many highly qualified individuals who gladly help for free. Stevie
is not one of them, but he is the only one who just does not get the idea of
"FREE" support. He offers questionable results at unreasonable prices. If he
was any good, the "thousands" of people he claims to have helped would be
flooding him with work, but there appears to be a continuous drought and he
needs to constantly grovel for work.

A few gems gleaned from the Word New User newsgroup over the Christmas
holidays to show Stevie's "expertise" in Word.


Dec 17, 2008 7:47 pm

Word 2007 ..........
In older versions of Word you could highlght some text then go to Format -
Change Case and change the case of the hoghloghted text. Is this still
available in Word 2007? Where?
Thanks! Steve


Dec 22, 2008 8:22 pm

I am designing a series of paystubs for a client. I start in landscape and
draw a table then add columns and rows to setup labels and their
corresponding value. This all works fine. After a landscape version is
completed, I next need to design a portrait version. Rather than strating
from scratch, I'd like to be able to cut and paste from the landscape
version and design the portrait version.
Steve


Dec 24, 2008, 1:12 PM

How do you protect the document for filling in forms?
Steve


One of my favourites:
Dec 30, 2008 8:07 PM - a reply to stevie
(The original poster asked how to sort a list and stevie offered to create
the OP an Access database)
Yes, you are right but a database is the correct tool to use not a
spreadsheet.


Not at all. If it's just a simple list then a spreadsheet is perfectly
adequate...




John... Visio MVP
 
J

James A. Fortune

paulkemp39 said:
Hi can anyone help with the following using access 2003.

I am creating a report in access to give to our accounts department that
shows amounts of money to be paid out.
I am trying to work out the breakdown of a value into notes and coins.
e.g. person A made £46.36 so would need 2x£20 1x£5.00 1x£1 1x£0.20 1x£0.10
1x£0.05 and 1x£0.01
person B made ..... etc.
This would then be added up at the end and then a total for each
denomination would also be needed.
Total = 6 x £20.00 3 x £10 4 x £5.00 .... etc.

Many thanks in advance
paulkemp39

If the each denomination value is an exact multiple of the one below it,
then an easier query can be used.

tblEDenomination
DID AutoNumber
Denomination Dbl
DenominationName Text
DID Denomination DenominationName
1 20 Purple Note
2 10 tenner
3 5 beehive
4 1 quid
5 0.2 Tudor rose
6 0.1 florin
7 0.05 bob
8 0.01 pence

tblI
ID AutoNumber
I Long
ID I
1 1
2 2
3 3
....
20 20

tblBreakdown
BID AutoNumber
BreakdownAmount Currency
BID BreakdownAmount
1 £173.39

qryMakeEChange:
SELECT (SELECT A.Denomination FROM tblEDenomination AS A WHERE A.DID =
tblI.I) AS Denomination, Nz((SELECT A.Denomination FROM tblEDenomination
AS A WHERE A.DID = tblI.I - 1),0) AS PrevDenomination,
Int(tblBreakdown.BreakdownAmount/(SELECT A.Denomination FROM
tblEDenomination AS A WHERE A.DID = tblI.I - 1)) AS X,
Int(tblBreakdown.BreakdownAmount/(SELECT A.Denomination FROM
tblEDenomination AS A WHERE A.DID = tblI.I)) AS Y,
BreakdownAmount-Y*Denomination AS Remainder, BreakdownAmount -
Nz(X,0)*PrevDenomination AS PrevRemainder,
(PrevRemainder-Remainder)/Denomination AS HowMany, (SELECT
A.DenominationName FROM tblEDenomination AS A WHERE A.DID = tblI.I) AS
DenominationName, CCur(HowMany * Denomination) As Extended FROM
tblBreakdown, tblI WHERE tblI.I<=(SELECT Count(*) FROM tblEDenomination)
ORDER BY tblBreakdown.BID, tblI.I;

!qryMakeEChange:
Denomination PrevDenomination X Y Remainder HowMany BreakdownAmount Extended
20 0 Null 8 $13.39 $173.39 8 Purple Note $160.00
10 20 8 17 $3.39 $13.39 1 tenner $10.00
5 10 17 34 $3.39 $3.39 0 beehive $0.00
1 5 34 173 $0.39 $3.39 3 quid $3.00
0.2 1 173 866 $0.19 $0.39 1 Tudor rose $0.20
0.1 0.2 866 1733 $0.09 $0.19 1 florin $0.10
0.05 0.1 1733 3467 $0.04 $0.09 1 bob $0.05
0.01 0.05 3467 17339 $0.00 $0.04 4 pence $0.04

See:

http://bytes.com/topic/access/answers/647145-denomination-breakdown

James A. Fortune
(e-mail address removed)
 
P

paulkemp39

Hi thanks to all for such a quick response. I will now go away and try SOME
of these suggestions out and let you know how I get on. Also as john says
these are FREE help forums, we pay enough out just to live.

Many thanks PaulKemp39
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top