Results 1 to 10 of 10
  1. #1
    chavez_sea is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2011
    Posts
    105

    Look up formula

    Hi,
    I would like to make a formula in a query to look up whether a date falls within a range of beginning and ending date and return a week number from a table. Eg.



    Week Number Beginning Date Ending Date
    1 06-Jan-19 12-Jan-19
    2 13-Jan-19 19-Jan-19
    3 20-Jan-19 26-Jan-19

    Thanks for any help.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    =DLookup("WeekNumber", "tablename", "#" & [datefield] & "# BETWEEN [BeginningDate] AND [EndingDate]")
    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. #3
    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 a query I'd use a non-equi join. If there are a lot of records, a DLookup() can really slow down a query.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    chavez_sea is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2011
    Posts
    105
    This is the query:
    Wk: DLookUp("WeekNumber","TblWeek Numbers","#" & [datefield] & "# BETWEEN [BeginningDate] AND [EndingDate]")
    Give me a box EnterParamater Value Datefield, I press OK to bypass and then a syntax error ##Between BETWEEN [BeginningDate] AND [EndingDate'
    Please for your suggestions

  5. #5
    chavez_sea is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2011
    Posts
    105
    Thank you, However I am not familiar with non-equi join. WOuld you help me with this.

    Thanks

  6. #6
    chavez_sea is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2011
    Posts
    105
    Ok I changed the datefield to the field I want it to return now it is giving me an #error

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    The expression example I provided worked for me with my data. I don't know your data. Do your field names have spaces? If they do, must enclose in [ ] - [Week Number]

    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.

  8. #8
    chavez_sea is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2011
    Posts
    105
    Week Number Beginning Date Ending Date
    1 06-Jan-19 12-Jan-19
    2 13-Jan-19 19-Jan-19
    3 20-Jan-19 26-Jan-19
    4 27-Jan-19 02-Feb-19
    5 03-Feb-19 09-Feb-19


  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    So modify the examples as appropriate. Use your actual table and field names with their spaces.
    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.

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Quote Originally Posted by chavez_sea View Post
    Thank you, However I am not familiar with non-equi join. WOuld you help me with this.

    Thanks
    To your existing query against the transaction data you'd add the bits in red(in SQL View), using your table/field names:

    SELECT Field1, Field2..., PayrollTable.[Week Number]
    FROM TransactionTableName TT LEFT JOIN PayrollTable PR ON TT.[DateFieldName] >= PR.[Beginning Date] AND TT.[DateFieldName] <= PR.[Ending Date]
    WHERE...

    Note you won't be able to use design view as it can't represent a non-equi join. The DLookup() will return the same result, but if the table is large will likely be much slower.
    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. Replies: 19
    Last Post: 07-13-2015, 10:15 AM
  2. Replies: 41
    Last Post: 05-29-2015, 02:58 PM
  3. IRR Formula in VBA
    By Mpike926 in forum Access
    Replies: 2
    Last Post: 05-19-2015, 02:48 PM
  4. formula help
    By Paintballlovr in forum Forms
    Replies: 2
    Last Post: 11-22-2013, 03:22 PM
  5. SQL Formula to Sum Itself
    By Scorpio11 in forum Access
    Replies: 1
    Last Post: 02-19-2011, 11:22 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