Results 1 to 7 of 7
  1. #1
    Luis Ferreira is offline Novice
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Oct 2010
    Posts
    6

    Query for Report

    Hello All,



    I need help to find a solution for my "small" problem...

    Table Expenses
    Name - Jan - Fev - Mar - ... - Dec
    (Text - Value - Value - Value - ... - Value)

    Form Month Select
    StartMonth - EndMonth

    Report
    Name - Sum(of months selected in form Month Select)

    Thanks in advance

  2. #2
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    you need some VBA codes to do the calculation because you table design is not good for this calculation.

  3. #3
    Luis Ferreira is offline Novice
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Oct 2010
    Posts
    6
    Quote Originally Posted by weekend00 View Post
    you need some VBA codes to do the calculation because you table design is not good for this calculation.
    Any idea where i can obtain that VBA code?

    Thanks

  4. #4
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    1 Create a query to transfer you table:
    Query: UnionQry
    Code:
    SELECT Jan2Dec.Nname, 1 as mMonth, Jan2Dec.Jan as Expense FROM Jan2Dec union all
    SELECT Jan2Dec.Nname, 2 as mMonth, Jan2Dec.Feb FROM Jan2Dec union all
    SELECT Jan2Dec.Nname, 3 as mMonth, Jan2Dec.Mar FROM Jan2Dec union all
    SELECT Jan2Dec.Nname, 4 as mMonth, Jan2Dec.Apr FROM Jan2Dec union all
    SELECT Jan2Dec.Nname, 5 as mMonth, Jan2Dec.May FROM Jan2Dec union all
    SELECT Jan2Dec.Nname, 6 as mMonth, Jan2Dec.Jun FROM Jan2Dec union all
    SELECT Jan2Dec.Nname, 7 as mMonth, Jan2Dec.Jul FROM Jan2Dec union all
    SELECT Jan2Dec.Nname, 8 as mMonth, Jan2Dec.Aug FROM Jan2Dec union all
    SELECT Jan2Dec.Nname, 9 as mMonth, Jan2Dec.Sep FROM Jan2Dec union all
    SELECT Jan2Dec.Nname, 10 as mMonth, Jan2Dec.Oct FROM Jan2Dec union all
    SELECT Jan2Dec.Nname, 11 as mMonth, Jan2Dec.Nov FROM Jan2Dec UNION ALL 
    SELECT Jan2Dec.Nname, 12 as mMonth, Jan2Dec.Dec FROM Jan2Dec;
    2 set the vaules of your comboBox startMonth and EndMonth from 1 to 12,

    3 use following as data source of your report:

    select nName, sum(expense) as eExpense from unionqry where mMonth betwee forms!yourform.startMonth and forms!yourform.endMonth

  5. #5
    Luis Ferreira is offline Novice
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Oct 2010
    Posts
    6
    Quote Originally Posted by weekend00 View Post
    1 Create a query to transfer you table:
    Query: UnionQry
    Code:
    SELECT Jan2Dec.Nname, 1 as mMonth, Jan2Dec.Jan as Expense FROM Jan2Dec union all
    SELECT Jan2Dec.Nname, 2 as mMonth, Jan2Dec.Feb FROM Jan2Dec union all
    SELECT Jan2Dec.Nname, 3 as mMonth, Jan2Dec.Mar FROM Jan2Dec union all
    SELECT Jan2Dec.Nname, 4 as mMonth, Jan2Dec.Apr FROM Jan2Dec union all
    SELECT Jan2Dec.Nname, 5 as mMonth, Jan2Dec.May FROM Jan2Dec union all
    SELECT Jan2Dec.Nname, 6 as mMonth, Jan2Dec.Jun FROM Jan2Dec union all
    SELECT Jan2Dec.Nname, 7 as mMonth, Jan2Dec.Jul FROM Jan2Dec union all
    SELECT Jan2Dec.Nname, 8 as mMonth, Jan2Dec.Aug FROM Jan2Dec union all
    SELECT Jan2Dec.Nname, 9 as mMonth, Jan2Dec.Sep FROM Jan2Dec union all
    SELECT Jan2Dec.Nname, 10 as mMonth, Jan2Dec.Oct FROM Jan2Dec union all
    SELECT Jan2Dec.Nname, 11 as mMonth, Jan2Dec.Nov FROM Jan2Dec UNION ALL 
    SELECT Jan2Dec.Nname, 12 as mMonth, Jan2Dec.Dec FROM Jan2Dec;
    2 set the vaules of your comboBox startMonth and EndMonth from 1 to 12,

    3 use following as data source of your report:

    select nName, sum(expense) as eExpense from unionqry where mMonth betwee forms!yourform.startMonth and forms!yourform.endMonth

    Hello,
    First of all thank you for your interest in helping me.

    This is the Unnion Query I do:
    SELECT Jan2Dez.nConta, 0 as mMonth, Jan2Dez.Abe as Valor FROM [10273PlanoSoma] UNION ALL
    SELECT Jan2Dez.nConta, 1 as mMonth, Jan2Dez.Jan as Valor FROM [10273PlanoSoma] UNION ALL
    SELECT Jan2Dez.nConta, 2 as mMonth, Jan2Dez.Fev as Valor FROM [10273PlanoSoma] UNION ALL
    SELECT Jan2Dez.nConta, 3 as mMonth, Jan2Dez.Mar as Valor FROM [10273PlanoSoma] UNION ALL
    SELECT Jan2Dez.nConta, 4 as mMonth, Jan2Dez.Abr as Valor FROM [10273PlanoSoma] UNION ALL
    SELECT Jan2Dez.nConta, 5 as mMonth, Jan2Dez.Mai as Valor FROM [10273PlanoSoma] UNION ALL
    SELECT Jan2Dez.nConta, 6 as mMonth, Jan2Dez.Jun as Valor FROM [10273PlanoSoma] UNION ALL
    SELECT Jan2Dez.nConta, 7 as mMonth, Jan2Dez.Jul as Valor FROM [10273PlanoSoma] UNION ALL
    SELECT Jan2Dez.nConta, 8 as mMonth, Jan2Dez.Ago as Valor FROM [10273PlanoSoma] UNION ALL
    SELECT Jan2Dez.nConta, 9 as mMonth, Jan2Dez.Set as Valor FROM [10273PlanoSoma] UNION ALL
    SELECT Jan2Dez.nConta, 10 as mMonth, Jan2Dez.Out as Valor FROM [10273PlanoSoma] UNION ALL
    SELECT Jan2Dez.nConta, 11 as mMonth, Jan2Dez.Nov as Valor FROM [10273PlanoSoma] UNION ALL
    SELECT Jan2Dez.nConta, 12 as mMonth, Jan2Dez.Dez as Valor FROM [10273PlanoSoma] UNION ALL
    SELECT Jan2Dez.nConta, 13 as mMonth, Jan2Dez.Reg as Valor FROM [10273PlanoSoma] UNION ALL
    SELECT Jan2Dez.nConta, 14 as mMonth, Jan2Dez.Apu as Valor FROM [10273PlanoSoma];

    And didin't work.... He do not sum de values

  6. #6
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    the last query under step 3 sum the values:
    select nName, sum(expense) as eExpense from unionqry where mMonth betwee forms!yourform.startMonth and forms!yourform.endMonth

  7. #7
    Luis Ferreira is offline Novice
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Oct 2010
    Posts
    6
    Quote Originally Posted by weekend00 View Post
    the last query under step 3 sum the values:
    select nName, sum(expense) as eExpense from unionqry where mMonth betwee forms!yourform.startMonth and forms!yourform.endMonth

    Hello,

    Sorry for my delay. Your solution works very well.

    Thank You Very Much.

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

Similar Threads

  1. Report based on query + sub-report (1:N relation)
    By BayerMeister in forum Reports
    Replies: 1
    Last Post: 08-19-2010, 03:26 AM
  2. Replies: 3
    Last Post: 05-21-2010, 03:57 PM
  3. Query For A Specifications Report
    By cadsvc in forum Queries
    Replies: 0
    Last Post: 05-08-2010, 10:46 AM
  4. From which query is the report generated
    By rukmal82 in forum Reports
    Replies: 6
    Last Post: 09-30-2009, 09:28 AM
  5. Replies: 1
    Last Post: 02-02-2009, 05:52 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