Results 1 to 2 of 2
  1. #1
    Deutz is offline Advanced Beginner
    Windows Vista Access 2010 (version 14.0)
    Join Date
    Oct 2010
    Posts
    51

    Stop text box from rounding decimals

    Hi,



    I am using Access 2003 and have a form with a number of unbound text boxes formatted to Standard number, 2 decimal places.

    The problem is that whenever you enter a number with more than 2 decimals the textbox rounds the second decimal place up or down which I don't want. I just want to drop off any decimals greater than 2.

    For instance if I enter 12.225 in a textbox the value displayed is rounded up to 12.23 and I want it to display 12.22 and ignore the third decimal.

    I tried an input mask and that works but is not ideal for my purpose.

    Any suggestions?

    Thanks in advance

  2. #2
    Deutz is offline Advanced Beginner
    Windows Vista Access 2010 (version 14.0)
    Join Date
    Oct 2010
    Posts
    51

    Problem solved

    Thanks if you are looking at this but I just figured out how to do it by calling the sub below from the Lost Focus event of each textbox:
    (the sub trims off extra decimal places greater than 2)

    Sub StopTextboxRounding()
    Dim lngDec As Long

    With Me.ActiveControl
    If Not IsNull(.Value) Then
    lngDec = InStr(.Value, ".")
    If lngDec > 0 Then
    If Len(.Value) - lngDec > 2 Then
    .Value = Mid(.Value, 1, lngDec + 2)
    End If
    End If
    End If
    End With
    End Sub

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Number of decimals in sum function
    By arfo in forum Access
    Replies: 6
    Last Post: 12-02-2010, 09:08 AM
  2. Input mask frustration (decimals)
    By Remster in forum Forms
    Replies: 2
    Last Post: 10-29-2010, 09:33 AM
  3. Round Up/Down 4 Decimals to 2
    By newbie in forum Access
    Replies: 6
    Last Post: 10-18-2010, 02:58 PM
  4. Rounding off
    By Alex Motilal in forum Access
    Replies: 4
    Last Post: 12-20-2009, 12:47 PM
  5. Replies: 2
    Last Post: 11-29-2009, 12:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums