Filling out a date range with values based on most recent

I have a table like this:
Date     Value
1/1           3
5/1           5
7/1           8

And another like this:

I want to combine these tables into this
Date  Value
1/1    3
2/1    3
3/1    3
4/1    3
5/1    5
6/1    5
7/1    8
8/1    8

So in other words, it's like a left join from tblDates on tblValues where nulls yield that last (i.e. most recent) change value.  Restated, I want to know what change value is in effect for each date in the list.  If nothing matches, take the most recent.

This could be done with Domain functions (like DLast), but that's very cumbersome.  Is there a better way?
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.

Phillip BurtonDirector, Practice Manager and Computing ConsultantCommented:
It may be cumbersome, but it's probably the best way.

If this was SQL Server, then you could use the LAG function, but that's not present in Access.

Outside of DLast, you would have to do some JOINs with non-equal comparisons, and if you have a big table, that would get slow - so Domain functions are probably the best for Access.
Phillip BurtonDirector, Practice Manager and Computing ConsultantCommented:
Here's the SQL for the query with non-equal comparisons. It might not be as slow as I was fearing:

SELECT qryRelevantDate.Date, tblChanges.Value
FROM (SELECT tblDates.Date, Max(tblChanges.Date) AS MapDate
FROM tblDates INNER JOIN tblChanges ON tblDates.Date >= tblChanges.Date
GROUP BY tblDates.Date) as qryRelevantDate INNER JOIN tblChanges ON qryRelevantDate.MapDate = tblChanges.Date;

Open in new window

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
Phillip BurtonDirector, Practice Manager and Computing ConsultantCommented:
This is the output:

Date	Value
01/01/2014	3
02/01/2014	3
03/01/2014	3
04/01/2014	3
05/01/2014	5
06/01/2014	5
07/01/2014	8
08/01/2014	8

Open in new window

Gustav BrockCIOCommented:
Why not pick the values directly:

    (Select Max(tblChanges.Value)
    From tblChanges
    Where tblChanges.Date <= tblDates.Date) As [Value]

shachoAuthor Commented:
Yep, that does the trick, Phillip.
Thanks all for your comments!

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.