Hi, I couldn't get around a problem about decimal rounding up when adding a record to a table from a form by programming a button.
I have an invoice form where the grand total is a calculated text field. The command button "cmdProcess " is supposed to add some fields (customer no, invoice date, grand total (as receivable), currency etc) to a table which keeps track of customer transactions. However, the decimals of grand total field is rounded up to integer (Funny, this does not happen with the command button that opens a report and prints the invoice).
The txtGrandTotal field on the form is standard with decimals set to 2, so is the receivable field in the table.
Here's the code (changed names to English for better understanding):
thanks in advance for any ideas
I have an invoice form where the grand total is a calculated text field. The command button "cmdProcess " is supposed to add some fields (customer no, invoice date, grand total (as receivable), currency etc) to a table which keeps track of customer transactions. However, the decimals of grand total field is rounded up to integer (Funny, this does not happen with the command button that opens a report and prints the invoice).
The txtGrandTotal field on the form is standard with decimals set to 2, so is the receivable field in the table.
Here's the code (changed names to English for better understanding):
Code:
Private Sub cmdProcess_Click()
Dim db As Database
Dim rstTransaction As DAO.Recordset
Dim intAns As Integer
Set db = CurrentDb
Set rstTransaction = db.OpenRecordset("tbl_AccountTransaction")
rstTransaction.Index = "InvoiceNo"
rstTransaction.Seek "=", Me.InvoiceNo
If rstTransaction.NoMatch = False Then
intAns = MsgBox("Invoice is already processed. Update?", vbYesNo)
If intAns = vbYes Then
rstTransaction.Edit
rstTransaction("trsCustNo").Value = Me.CustNo
rstTransaction("trsDate").Value = Me.date
rstTransaction("InvoiceNo").Value = Me.InvoiceNo
rstTransaction("receivable").Value = Me.txtGrandTotal
rstTransaction("cur").Value = Me.cur
rstTransaction.Update
MsgBox "Customer receivable updated"
Else
Exit Sub
End If
Else
rstTransaction.AddNew
rstTransaction("trsCustNo").Value = Me.CustNo
rstTransaction("trsDate").Value = Me.date
rstTransaction("InvoiceNo").Value = Me.InvoiceNo
rstTransaction("recievable").Value = Me.txtGrandTotal
rstTransaction("cur").Value = Me.cur
rstTransaction.Update
rstTransaction.Update
MsgBox "Receivable added to customer account"
End If
rstTransaction.Close
Set rstTransaction = Nothing
Set db = Nothing
End Sub
Comment