473,404 Members | 2,137 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,404 software developers and data experts.

Decimal problem when adding data by vba

18
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):
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdProcess_Click()
  2.     Dim db As Database
  3.     Dim rstTransaction As DAO.Recordset
  4.     Dim intAns As Integer
  5.  
  6.     Set db = CurrentDb
  7.     Set rstTransaction = db.OpenRecordset("tbl_AccountTransaction")
  8.  
  9.     rstTransaction.Index = "InvoiceNo"
  10.     rstTransaction.Seek "=", Me.InvoiceNo
  11.  
  12.     If rstTransaction.NoMatch = False Then
  13.         intAns = MsgBox("Invoice is already processed. Update?", vbYesNo)
  14.             If intAns = vbYes Then
  15.                 rstTransaction.Edit
  16.                 rstTransaction("trsCustNo").Value = Me.CustNo
  17.                 rstTransaction("trsDate").Value = Me.date
  18.                 rstTransaction("InvoiceNo").Value = Me.InvoiceNo
  19.                 rstTransaction("receivable").Value = Me.txtGrandTotal
  20.                 rstTransaction("cur").Value = Me.cur
  21.                 rstTransaction.Update
  22.                 MsgBox "Customer receivable updated"
  23.             Else
  24.                 Exit Sub
  25.             End If
  26.     Else
  27.         rstTransaction.AddNew
  28.                 rstTransaction("trsCustNo").Value = Me.CustNo
  29.                 rstTransaction("trsDate").Value = Me.date
  30.                 rstTransaction("InvoiceNo").Value = Me.InvoiceNo
  31.                 rstTransaction("recievable").Value = Me.txtGrandTotal
  32.                 rstTransaction("cur").Value = Me.cur
  33.                 rstTransaction.Update
  34.         rstTransaction.Update
  35.  
  36.         MsgBox "Receivable added to customer account"
  37.     End If
  38.     rstTransaction.Close
  39.     Set rstTransaction = Nothing
  40.     Set db = Nothing
  41.  
  42. End Sub
  43.  
thanks in advance for any ideas
Nov 4 '08 #1
3 2616
FishVal
2,653 Expert 2GB
Hello, Celal.

Are you sure tbl_AccountTransaction.[receivable] field has an appropriate data type?

Regards,
Fish
Nov 4 '08 #2
Celal
18
Fish,

Thanks a lot for your warning.. I realized the field was long integer in stead of single. I have overlooked and took your time (also spent my time) for such a simple mistake. Sorry about that.

Celal
Nov 6 '08 #3
FishVal
2,653 Expert 2GB
Hello, Celal.

You don't need to apologise.
Glad you've found solution.

Best regards,
Fish
Nov 6 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: Batista, Facundo | last post by:
Here I send it. Suggestions and all kinds of recomendations are more than welcomed. If it all goes ok, it'll be a PEP when I finish writing/modifying the code. Thank you. .. Facundo
17
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number....
2
by: Carl G | last post by:
I am storing a 0.000 a System.Decimal in a DataRow. On retrieval the value is only 0 without the three decimal places. It looks like the Get property returns System.Decimal.Zero, but why???? I...
7
by: hana1 | last post by:
Hello experts, I used to program in C/C++ and now switched to Java. I am having a difficulty that I need your help with. How can I limit a double variable to hold 2 decimal points only? Say I...
3
by: JenHu | last post by:
Hi all, I have to read from a text file and generate values and insert to database. But first of all, when the text file contains '0000000000', I received a sEfundAmt value = 0D instead of 0.0...
1
by: bunty.gopal | last post by:
This is the solution to the issue in the subject, question itself was posted in a previous thread long back. Use the latest DB2 db2cc.jar fixpack on the client, or add "deferPrepares=false" to...
25
by: Lennart Benschop | last post by:
Python has had the Decimal data type for some time now. The Decimal data type is ideal for financial calculations. Using this data type would be more intuitive to computer novices than float as its...
17
by: D'Arcy J.M. Cain | last post by:
I'm not sure I follow this logic. Can someone explain why float and integer can be compared with each other and decimal can be compared to integer but decimal can't be compared to float? True...
2
by: Rosco | last post by:
Problem: Using the sub routing below, when adding a value to another value the results eventually change from 2-decimal places to multiple decimal places. Basically, the amount stored should...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.