Results 1 to 10 of 10
  1. #1
    oton is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Mar 2018
    Posts
    4

    Question Get value from another table - Dlookup maybe?

    Hi champs!

    I tried to find the best way of doing it but no luck so far. Could anyone help?

    I have 2 tables and I need to (automatically) get into one of the tables a very specific value (Quarter) from another table based on a Date Range. Here it is:


    Table 1:

    ContractID Client ContractDate Quarter
    1 Client A 23-Mar-18 ?
    2 Client B 07-Jun-18 ?
    3 Client C 16-Aug-18 ?


    Contract Number (auto number)
    Contract End Date
    Quarter (automatically from table "Quarter Matrix based on the Contract End Date Field)

    Table 2:



    Quarter Start Date End Date
    Q1 01-Jan-18 30-Mar-18
    Q2 31-Mar-18 29-Jun-18
    Q3 30-Jun-18 28-Sep-18
    Q4 29-Sep-18 28-Dec-18



    Essentially, I need (either on the actual table 1 or on a query) MS Access to auto populate the Field "Quarter" using the "Contract End Date" from table 1 as reference to lookup from table 2.

    Tried in so many ways (IIF, Dlookup, etc) but I cannot get it right.

    I have attached the MS file simple sample just in case someone may want to see what that looks like.

    any help?
    Attached Files Attached Files

  2. #2
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    One way of doing this as a select query is to use both tables with no join (aka Cartesian join) then filter where contract date is between start date and end date
    See query qrySelectQtr in the attached database

    If you want to populate the field in the Contracts table, use an update query based on the first query

    NOTE: I've added 2 more records for info - one for 16/12/2018 (Q4) and another for 29/12/2018
    As the last date isn't in your table, the Qtr field is left blank
    Attached Files Attached Files
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    I've never seen quarter periods that didn't begin and end with first and last days of months. This would allow use of DatePart() function to calculate the quarter.

    Cartesian relationship query and DLookups() can perform slowly with very large datasets.

    Here is the correct DLookup() if you want to test for comparison:

    SELECT Contracts.*, DLookUp("Quarter","Quarter Matrix","#" & [ContractDate] & "# BETWEEN [Start Date] AND [End Date]") AS QTR FROM Contracts;


    Advise not to use spaces nor punctuation/special characters (underscore only exception) in naming convention.
    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.

  4. #4
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Quote Originally Posted by June7 View Post
    I've never seen quarter periods that didn't begin and end with first and last days of months. This would allow use of DatePart() function to calculate the quarter.
    Strangely this is the third post I've answered in the last fortnight with non-standard quarters.
    Another was the teams database by Daisy509

    Whoever decided on these dates needs to be hung, drawn & quartered!!!!
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    A bit bloody for me. I'll settle for tarred and feathered and run out of town on rails!

    Missed that detail about Daisy509th database.
    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.

  6. #6
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    The 'quartered' bit seems more appropriate somehow
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  7. #7
    oton is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Mar 2018
    Posts
    4
    Quote Originally Posted by ridders52 View Post
    One way of doing this as a select query is to use both tables with no join (aka Cartesian join) then filter where contract date is between start date and end date
    See query qrySelectQtr in the attached database

    If you want to populate the field in the Contracts table, use an update query based on the first query

    NOTE: I've added 2 more records for info - one for 16/12/2018 (Q4) and another for 29/12/2018
    As the last date isn't in your table, the Qtr field is left blank
    Brilliant !.. Ridder52..
    that was exactly what I needed.
    Thanks a Lot !!

  8. #8
    oton is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Mar 2018
    Posts
    4
    Hello Champs

    The reason behind the funny dates behind the Quarter is an internal financial calendar which does not follow the standard calendar... that is y.

    Thanks a lot for the help

    Quote Originally Posted by ridders52 View Post
    Strangely this is the third post I've answered in the last fortnight with non-standard quarters.
    Another was the teams database by Daisy509

    Whoever decided on these dates needs to be hung, drawn & quartered!!!!

  9. #9
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Glad you're happy with it.
    What about the final three days of the year?
    How will you manage future years? For example Q1 2019?
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  10. #10
    oton is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Mar 2018
    Posts
    4
    Hi Ridders52

    By the end of 2018 the dates for 2019 will be defined and entered on the Quarter Matrix. That will drive all new entries on the contract table.

    Thanks again


    Quote Originally Posted by ridders52 View Post
    Glad you're happy with it.
    What about the final three days of the year?
    How will you manage future years? For example Q1 2019?

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

Similar Threads

  1. Replies: 29
    Last Post: 05-02-2017, 04:38 PM
  2. DLookup from Another Table
    By SteveHale in forum Access
    Replies: 2
    Last Post: 12-14-2016, 06:06 PM
  3. Replies: 1
    Last Post: 03-22-2013, 03:33 AM
  4. Replies: 4
    Last Post: 05-09-2012, 07:20 AM
  5. Replies: 1
    Last Post: 08-13-2011, 12:03 AM

Tags for this Thread

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