Results 1 to 4 of 4
  1. #1
    ilpara87 is offline Novice
    Windows 10 Office 365
    Join Date
    Oct 2022
    Posts
    2

    Exclamation calculated field in query

    Hello everybody,


    I ask you for help regarding a problem in calculating a field in an access query where the calculation formula is stored in a parametric table that I use in join. let me explain: I have a table in which there are two "key" columns and another 3 columns in which there are values

    KEY_1 KEY_2 field_3 field_4 field_5
    A 1 0,5 0,1 0,2
    A 2 0,8 0,6 0,8
    A 3 0,8 0,9 0,1
    B 1 0,4 0,2 0,8
    B 2 0,4 0,3 0,4



    then I built a table in which I mapped the various formulas based on the combination of the first two key fields

    KEY_1 KEY_2 FORMULA
    A 1 [field_3] + [field_5]
    A 2 [field_4] * [field_5]
    A 3 [field_4] * 12,7
    B 1 [field_3] + [field_4]
    B 2 [field_3] / [field_4] * 7


    How can I make a query in which by joining the two tables I get a new "value" field in which the formula contained in the "formula" field of the second column is calculated? currently the system returns me the string field with the contents of the "formula" field (eg "[field_3] + [field_5]") instead I would like it to return the result of the calculation 0.7 (0.5 + 0.2).


    Can anyone help me out?
    thanks

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    You write a function to do just that.

    Then use that in the query.

    However your data does not look normalised?
    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
    ilpara87 is offline Novice
    Windows 10 Office 365
    Join Date
    Oct 2022
    Posts
    2
    how should i write the function? I have to write all the syntax of the sql or how? I made several attempts but failed as you suggested

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    No, you would, or at least I would approach it by
    Write a function that....
    Received the five parameters key, key2, field3, field4 and field5
    Then retrieve the formula for those keys.
    Then split that formula into 3 parts, fieldnumber1, operand and fieldnumber2

    Then do the math and return the result.

    Might be easier if you just use 3 + 5, instead of field_3 + field_5, as you will need to retrieve the numbers from the string. Just one less step to take.
    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. Replies: 1
    Last Post: 02-03-2016, 06:54 PM
  2. Replies: 2
    Last Post: 12-30-2014, 01:32 PM
  3. Replies: 1
    Last Post: 08-25-2014, 01:23 PM
  4. Replies: 4
    Last Post: 03-20-2014, 03:52 PM
  5. Replies: 3
    Last Post: 02-13-2013, 10:15 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