473,394 Members | 1,750 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

DateAdd and IIf

Having a few problems putting together an expression with DateAdd and IIf together on a form i have in Access 2003.

Not sure if i am doing this right but I am using a macro with SetValue to run On Exit from field [Frequency of Monitoring] to calculate a new date for the field [Assessment Review Date], depending on the choice made from [Frequency of Monitoring] e.g. "1 Month", "3 Month".
Under SetValue in macro i have set Item as [Assessment Review Date] but not sure how to write statement so that if 1 Month selected from [Frequency of Monitoring] then DateAdd will add 1 month from [Date] field to enter new date +1 month in {Assessment Review Date] or if 3 Months selected, enter new date +3months
Mar 19 '07 #1
15 3951
Rabbit
12,516 Expert Mod 8TB
Try:
Expand|Select|Wrap|Line Numbers
  1. iif([Frequency of Monitoring] = "1 Month", DateAdd("m", 1, [Date Field]), DateAdd("m", 3, [Date Field]))
Mar 19 '07 #2
Thanks. ;) This works a treat but i want to allow a choice of review dates greater than just 1month and 3 month and it to return the appropriate value e.g. +1 month, +3 month, +6 month and +1 year.
Any ideas?
Mar 20 '07 #3
Rabbit
12,516 Expert Mod 8TB
Thanks. ;) This works a treat but i want to allow a choice of review dates greater than just 1month and 3 month and it to return the appropriate value e.g. +1 month, +3 month, +6 month and +1 year.
Any ideas?
Nested iif statements or VBA code.
Mar 20 '07 #4
Nested iif statements if that is easier to just add to my expression in SetValue Macro or VBA if this is more robust.

Cheers! Should make myself a bit clearer.
Mar 20 '07 #5
Rabbit
12,516 Expert Mod 8TB
A nested iif statement is a quick and dirty fix, I would go with the VBA code, takes more time but is more robust.
Mar 20 '07 #6
Sorry but any idea how i would write this in VBA? Would i still add it as code on the OnExit property from [Frequency of monitoring] field?

Thanks
Mar 20 '07 #7
Denburt
1,356 Expert 1GB
Just a suggestion but I would add 1 more box probably combo set it to Value list and that box could be used to choose month, day, or year. Then on the properties sheet where it has the "On Exit from field" set this to [Event Procedure] Click the little icon to the right and it takes you right into the VBA area.

In this area you will want to set up some error trapping etc. (Search Google "VBA Error Trapping").

Then in the center add this:

Expand|Select|Wrap|Line Numbers
  1. Select Case Me!MyIncrement
  2.   Case "Days"
  3.     Me![Assessment Review Date] = DateAdd("m", 1, Me![Date Field]), 
  4.   Case "Months"
  5.  
  6.  case "Years"
  7.  
  8. End select
  9.  
Get the idea?
Mar 20 '07 #8
Rabbit
12,516 Expert Mod 8TB
Except days would be "d", Months "m", and Year "yyyy"
But basically a select case would be the best solution, you just have to fill in the blanks.
Mar 20 '07 #9
Denburt
1,356 Expert 1GB
LOL yeah oops thanks for that clarification Rabbit. Fingers going faster than my brain. Guess I should preview my posts.
Mar 20 '07 #10
Thanks for this. I have followed your code and it works great. I have sweated over this for a while.

Just to add the icing on the cake can i add anything to the code so that if i change the [Date field] to an earlier or later date rather than default todays date on the form but leave [Assessment Review Period] as it was e.g. at "3 Month" it will update the [Assessment Review Date] field.

At the moment if i go back and change the [Date field] i have to reselect the [Assessment Review Period] to calculate my new [Assessment Review Date]

Any ideas?

Cheers
Mar 20 '07 #11
Denburt
1,356 Expert 1GB
First I would take the select statement and place it in its own sub routine then call the routine from both of the controls on update events.

In the same forms module it would look something like this.
Expand|Select|Wrap|Line Numbers
  1. Private Sub  Date_field_AfterUpdate()
  2. MyInc
  3. End sub
  4.  
  5.  
  6. Private Sub Assessment_Review_Period_AfterUpdate()
  7. MyInc
  8. End sub
  9.  
  10.  
  11. Private Sub MyInc() 
  12. Select Case Me!MyIncrement
  13.   Case "Days"
  14.     Me![Assessment Review Date] = DateAdd("d", 1, Me![Date Field]), 
  15.   Case "Months"
  16.  
  17.  case "Years"
  18. End select
  19. End Sub
  20.  
Mar 20 '07 #12
Cheers. Got it working like a dream. I got the "d" days and "m" month bit. At least your fingers can go quicker than the brain.
Mar 20 '07 #13
Denburt
1,356 Expert 1GB
Glad I could help and as far as the brain thing I feel as though I have completely lost that sucker at times. ;)
Mar 20 '07 #14
Rabbit
12,516 Expert Mod 8TB
LOL yeah oops thanks for that clarification Rabbit. Fingers going faster than my brain. Guess I should preview my posts.
Not a problem, I do it too. The only difference between me and you is that I get to go back and edit my errors and make myself look better.
Mar 21 '07 #15
Denburt
1,356 Expert 1GB
Not a problem, I do it too. The only difference between me and you is that I get to go back and edit my errors and make myself look better.
LOL so not fair... :)
Mar 21 '07 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: lofty | last post by:
Dear Lord, I'm trying to code a drop down for a date entry that gives the user the option of the current date plus the dates of the last 7 days. <% for i = -7 to -1 Response.write...
4
by: Øyvind Isaksen | last post by:
Hi! I need to add 1 day to a specific date. The date have is stored in a variable called "DateOld". The value of the variable have this syntax: mm.dd.yyyy. The new date is the variable called...
9
by: Brandon | last post by:
Greetings, I am having a problem getting a SQL statement that is functional in Access 2K to work in ASP. My Access SQL statement is this: SELECT DateAdd('s',Ticket_Opened_Date,'Dec 31, 1969...
0
by: Zlatko Matiæ | last post by:
I am currently migrating from MSDE to PostgreSQL and have to rewrite the function that is calculating next date of sampling... In MSDE there is a DateAdd function. I can't find the appropriate...
1
by: Raghu | last post by:
Hello... I am running into a problem while running a query..can some1 help.. this is the query : ************** SELECT * from Table S where S.dtDate1 BETWEEN...
2
by: Abdul N K | last post by:
I need help in T-SQL. I am using DATEADD function and I want to add 6 months to a date. But it does not return me the rusults, which I want e.g. SELECT DATEADD(m,'20040630') returns 20041230...
3
by: Annette Massie | last post by:
I am trying to insert a record into a table via code and one of the values to add I would like as a dateadd calculation on a value from a query. My code looks like this: Set db = CurrentDb() ...
4
by: ey.markov | last post by:
Greetings, I have an A2K application where for a report the user enters a month-end date, and the system must gather transactions for that month. No problem, I thought, I'll just use the DateAdd...
1
by: C.Davidson | last post by:
Does subject VB.net 2003 support DateAdd function? I have tried to implement the following without success. In my example I tried to simply add 30 months to 9/18/2003 and I get "New date: 12:00:00...
2
by: Rich Raffenetti | last post by:
I have the following code. If I do the dateadd function with dateinterval.minute, it works fine and the date/time value is displayed with zero seconds. If I do the dateadd function with...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.