nearest date in two tables -- help

greenfalcon

Registered User.
Local time
Yesterday, 22:04
Joined
Aug 22, 2006
Messages
34
Hi all, Quick question...

i am trying to grab the nearest date using vba...

I have two tables... (Table 1)

2/1/2008
3/1/2008
4/1/2008

and (table 2)

2/20/2008
2/21/2008
3/21/2008


What i want to be able to do is if someone is looking at value 3/1/2008 in table 1, it would show the date 2/21/2008 from table 2...

for more information a user has a form where they are able to select dates from (table 1) and based on this i want it to use vba because i need to make some calculations based on information in the table with the nearest date
is this possible and if so how, ive been having a hard time doing this
 
Last edited:
I suppose it is possible... You are recieving a date on a form...
Using Query1:
Select min(abs(Form.GivenDate - table2.RequiredDate)) MinDiff from table 2

Now create query2:
Select Table2.RequiredDate from table2, Query1
where Table2.RequiredDate = Form.Givendate - Query1.MinDiff
or Table2.RequiredDate = Form.Givendate + Query1.MinDiff

If you understand what I mean, it is semi pseudo code, cause I have havent tested it.
 

Users who are viewing this thread

Back
Top Bottom