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)
Benyaw616Asked:
Who is Participating?
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 FyeCommented:
Try:

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?
0
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.
Capture.JPG
0
Gustav BrockCIOCommented:
You can use:

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

/gustav
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Dale FyeCommented:
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)
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!!
0
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)
0
Gustav BrockCIOCommented:
That would be:

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

/gustav
0
Benyaw616Author Commented:
Thank you Gustav!!!!!!!
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.