Dlookup value from 1 table with date ranges from diff table with a single date

I can't believe i can't get this simple thing to work! not very happy.

i have 2 tables.. 1 with bookings and 1 with a BonusPeriod range.

in the Bookings table there is a field called [ServiceDate]

in the bonus table i have a field called [Period] which is text
i also have 2 dates, [StartDate] And [EndDate]

i need to Dlookup the Bonus table to return the Period field value based on where the [ServiceDate] falls.

i dont want to use VBA (i really need it to work within a query that inserts it's data into another table)

i've tried everything but had no joy

Expr1: DLookUp("[Period]","BonusPeriods","[ServiceDate]" Between "#[StartDate]#" And "#[EndDate]#")

Expr1: DLookUp("[Period]","BonusPeriods","[Staff_BookingsAndQuotes_Master].[ServiceDate]" Between "#[StartDate]#" And "#[EndDate]#")

Expr1: DLookUp("[Period]","BonusPeriods","(FormatDateTime([ServiceDate]),"yyyy-mm-dd") Between (FormatDateTime([BonusPeriods]![StartDate]),"yyyy-mm-dd") and (FormatDateTime([BonusPeriods]![EndDate],"yyyy-mm-dd"))))

Expr21: Nz(DLookUp("Period","bonusperiods","#" & "servicedate" & "# BETWEEN StartDate AND EndDate"),0)
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dale FyeOwner, Developing Solutions LLCCommented:

Expr21: Nz(DLookUp("Period","bonusperiods","[ServiceDate] BETWEEN #" & [StartDate] & "# AND #" & [EndDate] & "#"),0)

Another consideration is what if the [StartDate] or [EndDate] on a record is NULL?
Benyaw616Author Commented:
Hi Dale,

the bonusperiod table doesn't have any null fields, I've manually added the records myself (it's a reference table)

i've tried the sql code you mention above and it prompts me for the start and end date as a parameter and it also gives an error message.
Gustav BrockCIOCommented:
You can use:

    Table1.*, Table2.*
    Table1, Table2
    CDate([Period]) Between [StartDate] And [EndDate]

10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

Dale FyeOwner, Developing Solutions LLCCommented:
My bad, I was thinking that Service Date was in table BonusPeriods and that [StartDate] and [EndDate] were in the other table.

  Try this:

Expr21: Nz(DLookUp("Period","bonusperiods","#" & [ServiceDate] & "# BETWEEN [StartDate] AND [EndDate]"),0)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Benyaw616Author Commented:
Thank you so much dale! that work perfectly!!
Benyaw616Author Commented:
Hi Dale,

Is it possible for you to amend this code so it removes local date formats? i'm in the UK and it's applying the filter in the US format of mm/dd/yyyy instead of dd/mm/yyyy

it's a long time ago but i did change something similar to the number format and it removed this issue (i can't find it anywhere)
Gustav BrockCIOCommented:
That would be:

"#" & Format([ServiceDate], "yyyy\/mm\/dd") & "# BETWEEN [StartDate] AND [EndDate]"

Benyaw616Author Commented:
Thank you Gustav!!!!!!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.