A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Date



 
 
Thread Tools Display Modes
  #1  
Old June 4th, 2010, 06:52 PM posted to microsoft.public.access.gettingstarted
Sassy[_2_]
external usenet poster
 
Posts: 2
Default Date

I have a table with a start date column. I have created a query where I
include the start date from my table, I have created an expression to add 24
months to the start date but what I would like to also have is either the
specific date or the closest month of May.
for example Start date is July 1, 2008 if I add 24 months it will show July
1, 2010
What I would like to see is May 2010 as this the month that we identify
individuals that need to start a secondary process.

Very new to access and not that great with formulas
--
Thank You
Sassy
Ads
  #2  
Old June 4th, 2010, 11:44 PM posted to microsoft.public.access.gettingstarted
KenSheridan via AccessMonster.com
external usenet poster
 
Posts: 1,610
Default Date

By 'closest' do you mean the May preceding the date 24 months from the start
date? If so the following expression should do it:

Format(DateAdd("m",IIf(Month([StartDate]) 5,17 - Month([StartDate]),29 -
Month([StartDate])),[StartDate]), "mmmm yyyy")

If by 'closest' you mean the nearest May before or after the date 24 months
from the start date then you'd need something a little more complex. You'd
probably be better wrapping the code in a little function for this:

Public Function StartSecondary(dtmStart As Date) As String

Dim dtmTwoYears As Date

' get date two years ahead of start date
dtmTwoYears = DateAdd("yyyy", 2, dtmStart)

' if month between May and November get previous May
' else get next may
If Month(dtmTwoYears) = 5 _
And Month(dtmTwoYears) = 10 Then

StartSecondary = Format(DateAdd("m", IIf(Month(dtmStart) 5, 17 - _
Month(dtmStart), 29 - Month(dtmStart)), dtmStart), "mmmm yyyy")

Else

StartSecondary = Format(DateAdd("m", IIf(Month(dtmStart) 5, 29 - _
Month(dtmStart), 41 - Month(dtmStart)), dtmStart), "mmmm yyyy")

End If

End Function

For this I've assumed that for a date between May and November the 'closest'
May would be the previous one, after November, the next one. Just paste the
function into a standard module. Save the module under a different name from
the function, e.g. basDateStuff. The function can then be called in a
computed column query, passing the StartDate value into it:

StartSecondary([StartDate])

Ken Sheridan
Stafford, England

Sassy wrote:
I have a table with a start date column. I have created a query where I
include the start date from my table, I have created an expression to add 24
months to the start date but what I would like to also have is either the
specific date or the closest month of May.
for example Start date is July 1, 2008 if I add 24 months it will show July
1, 2010
What I would like to see is May 2010 as this the month that we identify
individuals that need to start a secondary process.

Very new to access and not that great with formulas


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...arted/201006/1

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 09:12 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright 2004-2017 OfficeFrustration.
The comments are property of their posters.