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): - 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
-
thanks in advance for any ideas
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
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
FishVal 2,653
Recognized Expert Specialist
Hello, Celal.
You don't need to apologise.
Glad you've found solution.
Best regards,
Fish
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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...
|
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
|
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...
|
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
| |
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
|
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...
|
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.
|
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
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |