Benyaw616
asked on
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]","BonusP eriods","[ ServiceDat e]" Between "#[StartDate]#" And "#[EndDate]#")
Expr1: DLookUp("[Period]","BonusP eriods","[ Staff_Book ingsAndQuo tes_Master ].[Service Date]" Between "#[StartDate]#" And "#[EndDate]#")
Expr1: DLookUp("[Period]","BonusP eriods","( FormatDate Time([Serv iceDate]), "yyyy-mm-d d") Between (FormatDateTime([BonusPeri ods]![Star tDate]),"y yyy-mm-dd" ) and (FormatDateTime([BonusPeri ods]![EndD ate],"yyyy -mm-dd"))) )
Expr21: Nz(DLookUp("Period","bonus periods"," #" & "servicedate" & "# BETWEEN StartDate AND EndDate"),0)
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]","BonusP
Expr1: DLookUp("[Period]","BonusP
Expr1: DLookUp("[Period]","BonusP
Expr21: Nz(DLookUp("Period","bonus
ASKER
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
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
You can use:
Select
Table1.*, Table2.*
From
Table1, Table2
Where
CDate([Period]) Between [StartDate] And [EndDate]
/gustav
Select
Table1.*, Table2.*
From
Table1, Table2
Where
CDate([Period]) Between [StartDate] And [EndDate]
/gustav
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you so much dale! that work perfectly!!
ASKER
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)
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)
That would be:
"#" & Format([ServiceDate], "yyyy\/mm\/dd") & "# BETWEEN [StartDate] AND [EndDate]"
/gustav
"#" & Format([ServiceDate], "yyyy\/mm\/dd") & "# BETWEEN [StartDate] AND [EndDate]"
/gustav
ASKER
Thank you Gustav!!!!!!!
Expr21: Nz(DLookUp("Period","bonus
Another consideration is what if the [StartDate] or [EndDate] on a record is NULL?