Page 2 of 2 FirstFirst 12
Results 16 to 24 of 24
  1. #16
    BRZ-Ryan is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    187

    Re: Query for date range

    So you're telling me I could leave the query as it was, add in the table with just three 5 dates and people table, and this would make it work add I'm trying to get it to work?

  2. #17
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Leave which query 'as it was'?

    I am suggesting 3 parts to this process.

    1. generate a dataset of all dates, either by DISTINCT query or by code writing to a temp table

    2. generate a dataset of all possible date/person pairs, either by Cartesian query or VBA code writing to a temp table

    3. generate a dataset of all date/person pairs and other data desired from the data table, either by query or VBA code writing to a temp table
    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.

  3. #18
    BRZ-Ryan is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    187

    Re: Query for date range

    As it was meaning it showing nothing for if an employee did not make an entry fire a given day, as noted in post #1.

    If there's no real performance benefit I may leave it as is bc I'm confused when you say to create a dataset of all people/date combinations. The only negative to the way I'm doing it now is if I have 50 employees, the query may be slow since its writing 250 records. If you care to explain more I'm all ears.

  4. #19
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    If you want the report to show a record for each person for each day and have it show 0 if there is no record in the data table, then need a dataset of all possible date and person combinations. Every date must be paired with every person.

    Then join that dataset to the data table (join type "Include all records from dates/people ...") and where a person has no record for a date in the data table, the data table fields will be blank.

    Don't know how to be more explicit with instructions. Did you even attempt the queries as described? Sometimes seeing is understanding.
    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.

  5. #20
    BRZ-Ryan is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    187

    Re: Query for date range

    I guess I don't understand the lingo entirely. When you say create a dataset of all dates/people then join it, do you mean a separate query or what? And would this query be a simple Select * From Dates, People;?? Remember, I'm still learning and thanks again for your help.

  6. #21
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    The 3 steps I outlined involve 3 datasets, each is either a table or a query, the latter two use the dataset produced in the step before them.

    So, yes, the dataset of all possible date/person pairs (step 2) is a simple SELECT query. Use the query builder as described.
    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.

  7. #22
    BRZ-Ryan is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    187

    Re: Query for date range

    I completely understand now. .

    Is it possible to do this with a single query via nesting? Or is it better to create a query object for all names/times, then query from that from my report query?

  8. #23
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Can nest if you want. Could build the SQL directly in the report RecordSource property. Can't say it's better either way.

    The all names/times in step 2 not what the report will be based on.

    Step 3 is the final dataset for report.
    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.

  9. #24
    BRZ-Ryan is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    187
    I think it's done, and in a single query. I just need to run a query when the report button is clicked to populate tblDay with the seleted date and 4 days after. Thanks again!

    tblDay = Table with the 5 dates
    tblPPL = Table of names
    tblData = self explanatory

    Code:
    SELECT PplDay.RepName, PplDay.TheDate, Nz(tblData.Item1,0), Nz(tblData.Item2,0), Nz(tblData.Item3,0)
    FROM (SELECT tblDay.[TheDate], tblPPL.[RepName] FROM tblDay, tblPPL) AS PplDay 
    LEFT JOIN tblData ON (PplDay.RepName = tblData.[RepName]) AND (PplDay.TheDate = tblData.[TheDate])
    GROUP BY PplDay.RepName, PplDay.TheDate, Nz(tblData.Item1,0), Nz(tblData.Item2,0), Nz(tblData.Item3,0);
    In my test, I populated data for Ryan only for all days except 1/30/14.

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Query for Range to encompass given date
    By Mattbro in forum Queries
    Replies: 2
    Last Post: 12-30-2013, 08:15 AM
  2. Date Range Query
    By need_help12 in forum Queries
    Replies: 7
    Last Post: 04-25-2012, 01:38 PM
  3. Run query by date range
    By ARickert in forum Access
    Replies: 2
    Last Post: 06-23-2011, 10:54 AM
  4. Complicated Query needs some date range help
    By KevinMCB in forum Queries
    Replies: 1
    Last Post: 01-11-2011, 12:25 PM
  5. Query for date range from two column?
    By sunny in forum Queries
    Replies: 2
    Last Post: 07-28-2010, 07:12 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