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.

Microsoft AccessSQL

Avatar of undefined
Last Comment
Pdeters

8/22/2022 - Mon
Rey Obrero (Capricorn1)

you will need vba codes to fill your field with dates

Kyle Abrahams

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
Kyle Abrahams

the above is for SQL.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Pdeters

ASKER
I would i use this SQL code in an Access query or do I need to use VBA
Kyle Abrahams

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.
Kyle Abrahams

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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Jeffrey Coachman

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
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.

Jeffrey Coachman

Pdeters,

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

Thanks

JeffCoachman
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
ASKER CERTIFIED SOLUTION
Rey Obrero (Capricorn1)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Pdeters

ASKER
Exactly what I am looking for
Thank you