Decimal problem when adding data by vba

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Celal
    New Member
    • Mar 2007
    • 18

    #1

    Decimal problem when adding data by vba

    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):
    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
    thanks in advance for any ideas
  • FishVal
    Recognized Expert Specialist
    • Jun 2007
    • 2656

    #2
    Hello, Celal.

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

    Regards,
    Fish

    Comment

    • Celal
      New Member
      • Mar 2007
      • 18

      #3
      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

      Comment

      • FishVal
        Recognized Expert Specialist
        • Jun 2007
        • 2656

        #4
        Hello, Celal.

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

        Best regards,
        Fish

        Comment

        Working...