Results 1 to 8 of 8
  1. #1
    tbjmobile@gmail.com is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    94

    How do I assign a data type to a calculated expression in a query?

    I have made several different queries with calculated fields on them and they work almost properly. What I need to know, is how to assign a data type to the calculated expressions. For instance, I have a field in the table with a currency data type and on the query I do a calculation on it to add a markup. When I open the query the calculated value is correct but it's just an integer with no currency symbol and no decimal places. That means that where the calculation results in a value that has say 50 cents, it won't show, so the calculation is then incorrect for my purposes.
    Thanks in advance for your help.

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,537
    Set the fields Format property. There are thousands of sites on Google that explain how. See:http://www.meadinkent.co.uk/acc-formatfields.htm
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    I don't think you can apply that kind of data type to a calculated field, but assuming it is returning a valid number (because your calculation is a numeric one), you can format the results however you want.
    In the Query Builder, simply right-click on the calculated field, select "Properties" and select the Currency option and the number of decimal places that you want.

    Note that there is also a FORMAT function, where you can format your result to show dollar sign and decimals, but this will actually return a Text value, which will be problematic if you need to use it in other calculations or criteria.


    EDIT: Too slow! Looks like Bob already replied.

  4. #4
    tbjmobile@gmail.com is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    94
    Thank you so much, Both, but especially Bob. I've spent about 2 hours this afternoon looking on Access Help, Google and other forums and got the same results but not what I was looking for. The properties sheet was already there staring at me ! Derrrrrrrrrrr.
    Thanks again.
    Trevor.

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    You probably don't know about data conversion functions, otherwise I think you would have at least mentioned you tried them. IIRC, they work in a calculated control, but I could be wrong about that. Look here for CCur and others. If nothing else, it will ensure you're aware of them if you're not already.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    tbjmobile@gmail.com is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    94
    Thanks Micron, looking now and printing off.

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    In retrospect I should point out that they convert data from one type to another, which may not be what you need to do. If for example, a table field is formatted to be a number and you try to convert a number to a string and store it in that field, you will raise an error. Likewise, some conversion functions don't play well with Nulls and will generate an error, such as if you try to convert Null to a date. Maybe I should have stayed out of this...

  8. #8
    tbjmobile@gmail.com is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    94
    Yes, I understand, but having the list of available functions will always be useful !

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

Similar Threads

  1. Replies: 8
    Last Post: 08-17-2023, 02:33 AM
  2. Replies: 6
    Last Post: 07-29-2016, 06:09 PM
  3. Replies: 5
    Last Post: 01-27-2016, 06:16 PM
  4. Replies: 1
    Last Post: 07-24-2014, 08:35 PM
  5. Replies: 2
    Last Post: 12-21-2013, 11:37 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