Link to home
Start Free TrialLog in
Avatar of Charlesdavid Allen
Charlesdavid AllenFlag for United States of America

asked on

Dlookup MSACCESS

Setup is basic.  Table (dbo_tblFMScheduleEffective) contains collumns "ScheduleNum", "EffectiveDateStart" and "EffectiveDateEnd"

I need to pull the appropriate ScheduleNum based on the LoanDate falling on or between the EffectiveDateStart and EffectiveDateEnd

Attempted to use a dlookup to do this.  May be a santax error, might be i need to use another method.

This is the buggy line.

intRateScheduleToUse = DLookup("[ScheduleNum]", "dbo_tblFMScheduleEffective", dtLoanDate & " >= [EffectiveDateStart] AND " & dtLoanDate & " <= [EffectiveDateEnd]")

Thank you in advance!
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Try this:

 intRateScheduleToUse = DLookup("[ScheduleNum]", "dbo_tblFMScheduleEffective", "#" & dtLoanDate & "#" & " >= " & "EffectiveDateStart" & " AND " & "#" & dtLoanDate & "#" & " <=" & "EffectiveDateEnd")

Your date variable (dtLoanDate) needs to be surrounded by pound signs.
ASKER CERTIFIED SOLUTION
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Charlesdavid Allen

ASKER

That did the trick. TY sir.
Note that DLOOKUP will only return the first value that meets the criteria. is this application so specific that you will only have a single record that meets that criteria?  If not, maybe you would be better off with a list, combo, or subform to display multiple records which meet this criteria.

Dale
@Dale

Indeed, as this is a lookup to determine which rate set based on effective date, and no effective dates can overlap (enforced); Only one result is ever possible.