Results 1 to 7 of 7
  1. #1
    DC CS is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Jan 2023
    Location
    Vaalpark, South Africa
    Posts
    70

    Storing a decimal in a table

    Hi all,


    I have a form with a subform where data is captured for purchase orders.
    The subform has the Items, quantity ordered and the price per unit.

    The table where it is stored, I have the PricePer as Number Type and Field Size set to Double.
    In the subform, the text field "Format" is "Currency".
    Although the user enters a number like "56.87" as the PricePer, the number is stored as "56" with no decimal.

    I changed the text format to "Fixed" with the "Decimal Places" to 2, but with the same result.

    I am saving the PricePer with this code:
    Val(Me!Frm_POsubform.Form!("Price" & i))
    In debug mode, it displays as 56 only. The text entered is 56.87.

    Any suggestions to fix?
    Thanks

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,943
    Why aren't you using Currency type and not Format?
    https://support.microsoft.com/en-us/...9-3418f622e482
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    DC CS is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Jan 2023
    Location
    Vaalpark, South Africa
    Posts
    70
    Hi,
    Sorry, I a have not made it clear. I am using Currency.

    I just tried to save the decimal number as a text into a numeric field in the table, and it is now saving the decimal part as well. Once I convert the string "12.33" with "Val(string)", it rounds the figure down to 12.

    Thanks

  4. #4
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    You should set the number type to Decimal and Format to Currency in your table.
    You will almost certainly get rounding errors using a double.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,943
    What are your local setting for the decimal point? a comma or an actual period?

    You said 'The table where it is stored, I have the PricePer as Number Type and Field Size set to Double.
    In the subform, the text field "Format" is "Currency".'


    That is NOT the same as setting the field to Currency type.

    Look at the link I posted.

    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    DC CS is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Jan 2023
    Location
    Vaalpark, South Africa
    Posts
    70
    Sorry for the confusion. My terminology not that great.
    I meant in the subform, the "Format" property of the TextBox is set to "Currency".

    Click image for larger version. 

Name:	Screenshot 2023-06-13 144802.jpg 
Views:	13 
Size:	37.4 KB 
ID:	50360

    Thanks

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,943
    Look at the pic. I am talking about the table, NOT the form. Format is just that a format, not a type.
    Attached Thumbnails Attached Thumbnails currency.PNG  
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. Convert decimal comma to decimal point
    By Hans Karlsson in forum Programming
    Replies: 3
    Last Post: 06-30-2014, 01:56 PM
  2. Storing an object in a table
    By Paul H in forum Programming
    Replies: 2
    Last Post: 08-26-2013, 07:28 AM
  3. Replies: 7
    Last Post: 08-09-2013, 12:04 AM
  4. Storing code in a table
    By jgelpi16 in forum Programming
    Replies: 4
    Last Post: 07-27-2011, 07:22 PM
  5. Storing an Equation in Table
    By tmedler in forum Programming
    Replies: 0
    Last Post: 03-09-2009, 09:25 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