Results 1 to 2 of 2
  1. #1
    Betra is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Posts
    1

    Same Field repeated with different values.

    Well Hello everyone, I'm not too sure what this is called and therefor no search results are even helping me.



    What im trying to do is, pull up 3 tables, and pull generic fields...

    So Right now this is where im at

    Code:
    SELECT Clients.ClientName, Contract.ClientCodeName, Contract.ClientCodeYear, Contract.SignedDate, Contract.ContractTotalHours, Contract.TermInMonth, Sum(Invoices.UsedHours) AS SumOfUsedHours, Sum(Invoices.UsedHours) AS u2
    FROM (Clients INNER JOIN Contract ON Clients.[ID] = Contract.[ClientID]) INNER JOIN Invoices ON Contract.ID = Invoices.ContractID
    GROUP BY Clients.ClientName, Contract.ClientCodeName, Contract.ClientCodeYear, Contract.SignedDate, Contract.ContractTotalHours, Contract.TermInMonth, Contract.Active, Clients.Company
    HAVING (((Contract.Active)=True) AND ((Clients.Company)=2))
    ORDER BY Clients.ClientName;
    Problem:
    there are three fields i want to add ([Invoices.UsedHours] based on Invoices.InvDate (this month, last month, and month before). this would give me the used hours for a 3 month period.

    Some help would be awesome!

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    The 3 fields you refer to are this month, last month, and month before? These aren't fields, this a range criteria. You want to retrieve records that fall within this range and Sum the UsedHours field.

    You can determine the first and last dates of the 3 month period and use that as criteria. A complication is having to consider crossing years.

    InvDate Between Month(DateAdd("m",-2,Date())) & "/1/" & Year(DateAdd("m",-2,Date())) And Date()

    That will use the current date to determine the 3-month range. Question is, do you want the current month? If it is March 1 and you run report do you want Jan, Feb, Mar or Dec, Jan, Feb? If you really want report to cover through the last full month, complicates the calculation even more because the ending date varies by month.

    InvDate Between CDate(Month(DateAdd("m",-3,Date())) & "/1/" & Year(DateAdd("m",-3,Date()))) And CDate(Month(Date()) & "/1/" & Year(Date())) - 1
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 4
    Last Post: 04-07-2011, 03:16 PM
  2. Use a lookup field to influence values in another field
    By nathanrt in forum Database Design
    Replies: 3
    Last Post: 01-13-2011, 03:40 PM
  3. Hi, How do we avoid repeated records?
    By radicrains in forum Queries
    Replies: 11
    Last Post: 11-04-2010, 03:00 AM
  4. Repeated rows in query-form
    By astraxan in forum Forms
    Replies: 2
    Last Post: 05-23-2010, 10:25 PM
  5. Combo Box without repeated values
    By SCFM in forum Access
    Replies: 2
    Last Post: 02-20-2010, 05:57 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