Results 1 to 14 of 14
  1. #1
    seb is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    73

    How to calculate

    Hello

    In an MS Acces 2016, I have a Form to search queries between dates.
    My union query works well.
    I need the total of the column Freq1 to use in a calculated field.
    However, I don't know how to calculate with sql the total of the column Feq.
    I attach my database and an excel file (zip)with the column /Prc) that I need in my query

    Your help is appreciated
    HTML Code:
    SELECT tbltaskmod.day, tbltaskmod.plot_id AS plot, tbltaskmodname.taskmodname AS taskmod, Sum(tbltaskmod.qty) AS Freq1FROM tbltaskmodname INNER JOIN (tblplot INNER JOIN tbltaskmod ON tblplot.Loteid = tbltaskmod.plot_id) ON tbltaskmodname.taskmod_id = tbltaskmod.taskmodname_idGROUP BY tbltaskmod.day, tbltaskmod.plot_id, tbltaskmodname.taskmodnameHAVING (((tbltaskmod.day) Between [Formularios]![frm_qrys_charts]![txtday1] And [Formularios]![frm_qrys_charts]![txtday2]))UNION SELECT tblbtask.day, tblbtask.plot_id AS plot, tblbtask_name.btask_name AS btast, Sum(tblbtask.qty) AS Freq2FROM tblbtask_name INNER JOIN (tblplot INNER JOIN tblbtask ON tblplot.Loteid = tblbtask.plot_id) ON tblbtask_name.btask_id = tblbtask.btask_idGROUP BY tblbtask.day, tblbtask.plot_id, tblbtask_name.btask_nameHAVING (((tblbtask.day) Between [Formularios]![frm_qrys_charts]![txtday1] And [Formularios]![frm_qrys_charts]![txtday2]));

    Attached Files Attached Files

  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
    One way would be to put a textbox with a DSum() on the form that pulled the total, then add it to your query:

    Round(Sum(tbltaskmod.qty)/[Forms]![frm_qrys_charts]![text9],4) AS Pct

    The DSum() could be in the query, but would be less efficient since it would be run for every record returned.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    seb is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    73
    If I write In the txtTotal =Sum([tbltaskmod].[qty]) and Error is displayed
    If I write in the TxtTotal = DSum=Suma([tbltaskmod].[qty]) a message "The expression you specified contains a function with an incorrect number of arguments" is displayed

    I do not know what I should write in the txtTotal

    Please help

  4. #4
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,740
    Code:
    TxtTotal = DSum("[qty]","[tbltaskmod]")

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    I suspect you'd want the same date criteria as well.

    http://www.theaccessweb.com/general/gen0018.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    seb is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    73
    davegri.Than you very much for your help.
    I wrote in the txttotal the code you recommended. However, an error (#¿Name?) is displayed.
    The Query I am calling is a Union Query from 2 tables.
    Any idea is welcome

  7. #7
    seb is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    73
    pbald.I am going to study the link. I hope to fins a solution.

  8. #8
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,740
    The Query I am calling is a Union Query from 2 tables.
    Well, your original post called for a sum in a table, not a query.
    It has to be like this:
    Code:
    txtTotal = Dsum("[field name in your query]","[query name]")
    Last edited by davegri; 10-30-2017 at 09:18 AM. Reason: syntax

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Okay, post back if you get stuck. I'm not sure you can use the query in the DSum(), as it may cause a circular reference, but you can try it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    seb is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    73
    Many Thanks.
    I really apologize if I did not say that I need the total from a union query.
    I have been unable to insert the correct code in txttotal.
    I attach my database.
    Attached Files Attached Files

  11. #11
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,740
    davegri_test1.zip
    Try the attached.
    I fixed errors in uqry_jar_modbtar which wouldn't run at all. Then added qty field to that query.
    Removed the expression in txttotal data property and set the value of that textbox in the cmb_search click_event.

  12. #12
    seb is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    73
    davegri. Smart code you sent me.
    I was kilometres away to find the solution.
    Thank you very much indeed.
    Last edited by seb; 10-30-2017 at 04:10 PM.

  13. #13
    seb is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    73
    paldy.
    In this post, davegri showed me how to calculate total in txttotal.
    Nevertheless, I still don't know where in my union query I have to include your code Round(Sum(tbltaskmod.qty)/[Forms]![frm_qrys_charts]![txttotal],4) AS Pct.
    I wrote txttotal instead of txt9

    Can you help me with this?
    Many thanks in advance,

  14. #14
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    In your original sample this worked:

    SELECT tbltaskmod.day, tbltaskmod.plot_id AS plot, tbltaskmodname.taskmodname AS taskmod, Sum(tbltaskmod.qty) AS Freq1, round(Sum(tbltaskmod.qty)/[Forms]![frm_qrys_charts]![text9],4) AS Pct

    You'd have to add to the second SELECT as well.
    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. How to calculate differences
    By ghodgkins in forum Access
    Replies: 5
    Last Post: 06-24-2015, 12:01 PM
  2. Replies: 2
    Last Post: 03-22-2015, 08:31 PM
  3. How to calculate 'half day'
    By Ayiramala in forum Access
    Replies: 11
    Last Post: 01-14-2015, 07:23 PM
  4. How to calculate?
    By cap.zadi in forum Queries
    Replies: 1
    Last Post: 11-09-2011, 07:29 AM
  5. calculate holidays
    By barkarlo in forum Queries
    Replies: 0
    Last Post: 12-20-2006, 06:08 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