Calculated expiration dates based on a field with no of extensions (1 Viewer)

lite4d

Registered User.
Local time
Today, 08:08
Joined
Apr 2, 2014
Messages
27
I'm trying to calculate expiration dates based on an original expiration date then if it can be extended based on the number in a field use that number then it will add the amount of months in another field and add it to the original expiration date. Here is what i have so far that doesn't work

Expiration: IIf([Total Shelf life]![no of Extensions]=1,DateAdd("m",[extension 1],[shelf life exp]))
 

jdraw

Super Moderator
Staff member
Local time
Today, 08:08
Joined
Jan 23, 2006
Messages
15,379
Can you add some context?
What exactly is the field name of original expiration date?
What is the time interval (months/days/weeks..) of an extension?
 

Minty

AWF VIP
Local time
Today, 13:08
Joined
Jul 26, 2013
Messages
10,371
Your table/field syntax is not correct. Try something like

Code:
CalcExpiration: IIf([Total Shelf Life].[no of Extensions] >=1, DateAdd("m",[Extension_1],[shelf life exp]),[shelf life exp])

This assumes that [Total Shelf Life] is the name of the table that [No of extensions] lives in?

Also, all those spaces in the field names table names make writing this stuff a nightmare. Field and table names should only have normal characters and possibly underscores in them, never spaces or special characters.
 

lite4d

Registered User.
Local time
Today, 08:08
Joined
Apr 2, 2014
Messages
27
jdraw, the original expiration date is (shelf Life Exp). I have a field that has the number of extensions(up to 3) and fields for the months that i can be extended for each extension.(18mo for first,12mo for second, 6mo for third extension). I need to take the shelf life expiration date and determine then number of extensions and the months those extensions are and come up with a new date for each expiration date. I have fields for each new date so I can do them one at a time.

Minty, that gave me a date but not for the number of months that it can be extended.

Thanks for the help!
 

Isaac

Lifelong Learner
Local time
Today, 05:08
Joined
Mar 14, 2017
Messages
8,777
jdraw, the original expiration date is (shelf Life Exp). I have a field that has the number of extensions(up to 3) and fields for the months that i can be extended for each extension.(18mo for first,12mo for second, 6mo for third extension). I need to take the shelf life expiration date and determine then number of extensions and the months those extensions are and come up with a new date for each expiration date. I have fields for each new date so I can do them one at a time.

Minty, that gave me a date but not for the number of months that it can be extended.

Thanks for the help!
You forgot the second part of the IIF.
Remember the IIF is "if this is true, then this, else that".
You forgot the "else that" portion.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 13:08
Joined
Feb 19, 2013
Messages
16,610
actually in access sql you can leave the else parameter out - it returns null if not specified.

also be interested to know what 'doesn't work' means
 

jdraw

Super Moderator
Staff member
Local time
Today, 08:08
Joined
Jan 23, 2006
Messages
15,379
As mentioned already, suggest you remove embedded spaces in field names.
If the number of extensions are always in 6 month increments, then an expression such as

ExpirationDate : DateAdd("m", NumberExtensions * 6, [TotalShelfLife].[ShelfLifeExp])

may be sufficient.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 08:08
Joined
Feb 19, 2002
Messages
43,266
Start by answering the question - do you need to keep history showing each extension?
If you don't, then you would use this code in your form when the user chooses to extend and specifies the number of months. Always keep the start date separate regardless of whether you need to maintain history or not.
 

Users who are viewing this thread

Top Bottom