473,803 Members | 3,637 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Decimal problem when adding data by vba

18 New Member
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 2638
FishVal
2,653 Recognized Expert Specialist
Hello, Celal.

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

Regards,
Fish
Nov 4 '08 #2
Celal
18 New Member
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 Recognized Expert Specialist
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
4542
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
6157
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. "Decimal Number" sometimes serves to distinguish Base 10 numbers, eg "15", from Base 2 numbers, Eg "1111". At other times "Decimal Number" serves to differentiate a number from an integer. For the rest of this post I shall only use either...
2
3605
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 can't figure out why the design is so that the DataRow "alters" the value entered. In my application a decimal column in a row of a specific table has a fix number of decimal places according to certain premises. The
7
43176
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 have an array of 50 doubles that each ahs a number such as 23.9918444. I want to round round this number to 23.99 and any other calculations done on it should have the same precision. I know that Decimal Format does the rounding but the thing that...
3
12925
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 on sEfundAmt = Decimal.Parse(Mid$(sRetLine, 30, 10)) / 100.0 For example, in the text file, value is '0000150776', I want to
1
5164
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 the connection string when opening the connection (or connection pool properties, if deployed on a server like weblogic). The issue can be resolved using either of these options. Gopal
25
3041
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 rounding behaviour matches more closely what humans expect. More to the point: 0.1 and 0.01 are exact in Decimal and not exact in float. Unfortunately it is not very easy to access the Decimal data type. To obtain the decimal number 12.34 one...
17
6816
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 True False This seems to break the rule that if A is equal to B and B is equal to C then A is equal to C.
2
2946
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 always only be 2 decimal places, because the values passed in are always 2 decimal places. Output from calling the sub routine multiple times. ... Running total = 329430.75 New Withheld Amount = 710.79 Running total = 330141.54
0
9703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9564
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10548
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9125
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7604
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5500
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5629
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2970
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.