Results 1 to 4 of 4
  1. #1
    RandV is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Mar 2013
    Posts
    12

    Change the decimal value of a field based on text value of another field?

    Let's say I have a plain text field for for unit of measurement, and a number field with 3 decimal places for quantity. All my reports have been built around a kilogram measurement, with space in the reports allocated for say 7 digits, 4 the left of the decimal and 3 on the right. Now on the database end I want to convert some of these existing kilograms into grams.

    In my reports the quantity field in the Details section is already a mathematical equation: =([Field1]*[Field2])/[Field3]. Is there a way in the report designer to to add on top of this to change the field format?

    Code:
    if unit.value = "GRM" then
       quantity.decimalplaces = 0
    else
       quantity.decimalplaces = 3
    End if
    In my ad hoc experience with Access reports anything in the details field can't be taken into VB for editing. Basically I want to verify if this is the case or if there is actually away to do this. I know I could set the decimal place to auto, go back to the program logic that prepares the tables the report runs on and hard code the the decimal places in or out, but that's going to be a whole lot of back work.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Code like that should work in the detail format event, provided you're using print or preview.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    RandV is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Mar 2013
    Posts
    12
    Quote Originally Posted by pbaldy View Post
    Code like that should work in the detail format event, provided you're using print or preview.
    Okay I'll have to give it another try then... I'm sure I've tried it before and was left with the impression that you couldn't. Thanks

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    No problem; I tested it so it should work.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 3
    Last Post: 06-20-2014, 02:30 PM
  2. Replies: 7
    Last Post: 04-23-2013, 11:57 AM
  3. Change Text field to Memo Field in a Query
    By Yarbz in forum Queries
    Replies: 5
    Last Post: 06-28-2012, 05:24 PM
  4. Replies: 1
    Last Post: 02-29-2012, 10:13 PM
  5. Replies: 2
    Last Post: 05-05-2010, 02:52 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