Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calcualted field is rounding off at the decimal, not displaying cents

Status
Not open for further replies.

Heeeeelp

Technical User
Jan 5, 2006
39
CA
Hi,

I need some urgent help.

I have four fields, txtAmount and txtBalance whcih are both unbound and formatted as currency. The txtAmount is populated by the user when they select an account from a drop down list. The txtBalance holds the balance after the calculation is made.
The other two fields, are in my BDAPayments table, PreAmt and RMBAmt. The user enters the amounts for these fields. The formats are currency for both and the decimal place is set at two.

Here is the code i'm using. I would really appreciate some assistance with this.

Function AmountAwarded(BDAAccID As Integer) As Long
Dim rst As DAO.Recordset
Dim db As Database

Set db = CurrentDb()
Set rst = db.OpenRecordset("BDA Allocations", dbOpenDynaset)

AmountAwarded = 0
Do Until rst.EOF
If rst!BDAAccID = BDAAccID Then
AmountAwarded = rst!Amount
Exit Do
End If
rst.MoveNext
Loop

rst.Close

End Function



Function Balance(BDAAccID As Integer) As Long
Dim rst As DAO.Recordset
Dim db As Database
Dim I, sumRec As Integer
Dim AmountAwarded As Long

Set db = CurrentDb()
Set rst = db.OpenRecordset("BDA Allocations", dbOpenDynaset)

AmountAwarded = 0
Do Until rst.EOF
If rst!BDAAccID = BDAAccID Then
AmountAwarded = rst!Amount
Exit Do
End If
rst.MoveNext
Loop

rst.Close


Balance = AmountAwarded

Set db = CurrentDb()
Set rst = db.OpenRecordset("BDA Payments", dbOpenDynaset)
Do Until rst.EOF
If rst!BDAAccID = BDAAccID Then
If IsNull(rst!RmbAmt) Then
With rst
.Edit
rst!RmbAmt = 0
.Update
End With
End If
If IsNull(rst!PreAmt) Then
With rst
.Edit
rst!PreAmt = 0
.Update
End With
End If
Balance = Balance - IIf(rst!RmbAmt = 0, rst!PreAmt, rst!RmbAmt)

End If

rst.MoveNext
Loop

rst.Close


End Function


Thank you,
Tess
 
The return type of both your functions is Long and that causes the returned values to be converted to 32-bit integers.

You probably need code like this
Code:
Function AmountAwarded(BDAAccID As Integer) As [COLOR=red]Currency[/color]

Function Balance(BDAAccID As Integer) As [COLOR=red]Currency[/color]

[small]No! No! You're not thinking ... you're only being logical.
- Neils Bohr[/small]
 
It works! Thank you Golom, that was really causing me grief.
I appreciate your help.
Tess
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top