Results 1 to 8 of 8
  1. #1
    deepakg27 is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2017
    Posts
    160

    Decimal Places In Calculated Field For Ms Access 2013

    Hi Guys,



    I am trying to make a simple invoicing database. I have created a calculated field Amount in tblSaleDetails where data type is set to double, Format to General Number & Decimal Places to 2. But still Access is calculating and saving upto four decimal places.

    For your reference Data base is attached. Your help is much appreciated.

    Thanks & Regards
    Deepak Gupta
    Attached Files Attached Files

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Format property is just for display. The data is not changed. The field is calculating 0 to 4 decimal places. Try the Fixed setting.

    For instance: 639.86 x 142.08 = 90911.3088

    Fixed format will show 90911.31 but the full value of 90911.3088 will be used in calcs.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    deepakg27 is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2017
    Posts
    160
    Hi June7,

    Thanks for the insight. But I need to store the data for upto two decimal places only (Like Round function with ,2). How can i do it?

    Thanks for your help. Much Appreciated.

    Regards
    Deepak Gupta
    Quote Originally Posted by June7 View Post
    Format property is just for display. The data is not changed. The field is calculating 0 to 4 decimal places. Try the Fixed setting.

    For instance: 639.86 x 142.08 = 90911.3088

    Fixed format will show 90911.31 but the full value of 90911.3088 will be used in calcs.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Then you can't use a calculated type field in table. Saving calculated data is usually unnecessary and/or ill-advised.

    Use code (VBA or macro) to save the calculated value. The calculation is simple. The real trick is figuring out what event to put the code into.

    Or calculate rounded value when it is needed.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    The top two lines of EVERY module should be
    Code:
    Option Compare Database
    Option Explicit
    "Date" and "Type" are reserved words in Access and shouldn't be used as object names. I renamed them.

    Having "ID" as the PK field name of every table is a poor naming convention. I renamed them (and the FK fields)

    See the relationship image......



    You have the "tblTaxRate" table PK field as an Autonumber, but the 3 related field(s) in "tblSalesDetail" are Text Type. Cannot set RI.


    You have Calculated fields and LookUp fields in your tables. I NEVER use Calculated fields and LookUp FIELDs.
    See:
    The evils of lookup fields - http://access.mvps.org/access/lookupfields.htm
    Table and PK design tips - http://www.fmsinc.com/free/newtips/primarykey.asp
    About calculated table fields - http://allenbrowne.com/casu-14.html




    Click image for larger version. 

Name:	Relationship1.png 
Views:	19 
Size:	150.0 KB 
ID:	31415

  6. #6
    deepakg27 is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2017
    Posts
    160
    Respected Ssanfu,

    Thanks for your guidance. I will try me level best to adhere to the rules of data normalization. Thanks for guiding me in the right direction. And special thanks to make my data look so beautiful and professional.

    Sir, in your data design could you please tell me what does RI stands for. Should I shift the 3 wrong field types to Number data type?

    Secondly, if we don't use lookup fields, how to show the name of the customer and information related to him in the invoice, while entering data.

    Thanks and Regards
    Deepak Gupta
    Quote Originally Posted by ssanfu View Post
    The top two lines of EVERY module should be
    Code:
    Option Compare Database
    Option Explicit
    "Date" and "Type" are reserved words in Access and shouldn't be used as object names. I renamed them.

    Having "ID" as the PK field name of every table is a poor naming convention. I renamed them (and the FK fields)

    See the relationship image......



    You have the "tblTaxRate" table PK field as an Autonumber, but the 3 related field(s) in "tblSalesDetail" are Text Type. Cannot set RI.


    You have Calculated fields and LookUp fields in your tables. I NEVER use Calculated fields and LookUp FIELDs.
    See:
    The evils of lookup fields - http://access.mvps.org/access/lookupfields.htm
    Table and PK design tips - http://www.fmsinc.com/free/newtips/primarykey.asp
    About calculated table fields - http://allenbrowne.com/casu-14.html




    Click image for larger version. 

Name:	Relationship1.png 
Views:	19 
Size:	150.0 KB 
ID:	31415

  7. #7
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by deepakg27 View Post
    Sir, in your data design could you please tell me what does RI stands for.
    RI stands for Referential integrity. See https://www.webopedia.com/TERM/R/ref...integrity.html and/or https://en.wikipedia.org/wiki/Referential_integrity
    If you do not have RI set, you just have a line between two fields.
    With RI set, you will see 1 at one end of the linking line (relationship) and the infinity symbol for the many side of the relationship. (1 to many)


    Quote Originally Posted by deepakg27 View Post
    Should I shift the 3 wrong field types to Number data type?
    If you want to set RI, then yes.


    Quote Originally Posted by deepakg27 View Post
    Secondly, if we don't use lookup fields, how to show the name of the customer and information related to him in the invoice, while entering data.
    I would use a main form/sub form arraignment; combo boxes would be used to select the data. In the main form (based on tblSales), select the customer/buyer. In the sub form (based on tblSalesDetails), select the invoice items from the combo boxes.

  8. #8
    deepakg27 is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2017
    Posts
    160
    Thanks Ssanfu.

    I would try and adhere to your suggestions. Will try to avoid lookup fields in future. I use lookup fields, as I work directly with tables. I will try and shift my working to forms.

    Thanks for the guidance. Looking for more in future.

    Regards
    Deepak Gupta

    Quote Originally Posted by ssanfu View Post
    RI stands for Referential integrity. See https://www.webopedia.com/TERM/R/ref...integrity.html and/or https://en.wikipedia.org/wiki/Referential_integrity
    If you do not have RI set, you just have a line between two fields.
    With RI set, you will see 1 at one end of the linking line (relationship) and the infinity symbol for the many side of the relationship. (1 to many)



    If you want to set RI, then yes.



    I would use a main form/sub form arraignment; combo boxes would be used to select the data. In the main form (based on tblSales), select the customer/buyer. In the sub form (based on tblSalesDetails), select the invoice items from the combo boxes.

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

Similar Threads

  1. Replies: 5
    Last Post: 03-09-2015, 01:57 PM
  2. Replies: 5
    Last Post: 02-26-2015, 11:22 AM
  3. Formatting for 3 decimal places
    By Triland in forum Forms
    Replies: 12
    Last Post: 01-24-2013, 10:49 AM
  4. Decimal Places
    By momodoujimnjie in forum Access
    Replies: 1
    Last Post: 01-09-2013, 04:49 AM
  5. many decimal places in calculated fields
    By GordS in forum Access
    Replies: 1
    Last Post: 02-04-2009, 11:12 AM

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