Link to home
Start Free TrialLog in
Avatar of Pdeters
Pdeters

asked on

Calculate Date - Show date every 3 months or every 4 months depending on criteria

I am not sure on the best way to do this

I am working with table that has 3 fields

Field1 is name
Field2 is StartDate
Field3 is Month Frequency

I want to create a query that calculates out the date by the number of months for 10 years.

So if the startDate for one is 1-1-06 and the frequency is every 3 months I would have a field with a  date in it for 10 years that shows a date of every 3 months.

Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

you will need vba codes to fill your field with dates

declare @dt as date
set @dt = startdate
declare #table as table
( name varchar(50), myDate  date)

while @dt < dateadd(year,10, startDate)
begin
   insert into #table name, @dt
   set @dt = dateadd(month, frequency, @dt)
end
the above is for SQL.
Avatar of Pdeters
Pdeters

ASKER

I would i use this SQL code in an Access query or do I need to use VBA
you can use my code to create a stored procedure in SQL then use a query to execute the stored procedure and select the rows from the temp table.
Create a pass through query to call a stored proc to the stored procedure.
http://www.access-programmers.co.uk/forums/showthread.php?t=34132
Pdeters,

Can you post a sample of the input, and a sample of what to ouput should be?

Without this, we are all just guessing as to what you need.

Thanks

JeffCoachman
Avatar of Pdeters

ASKER

Here is the sample Input Data

Field1            Field2            Field3
Sally            1-1-2004      4
Fred            2-5-2007      9
Ernie            10-5-2008      5

What I want then is to have a query or report that shows each starting at their startdate with a date showing then every 4 month increment. But not starting until the current month. So if 1-1-2004 next 4 month increment is 5-1-2009 (future) it will not show up on the 4-1-2009 report.

Pdeters,

Again, can you post the desired output?
That is what I am having trouble visualizing.

Thanks

JeffCoachman
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
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 Pdeters

ASKER

Exactly what I am looking for
Thank you