473,385 Members | 1,610 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,385 software developers and data experts.

Nested If with DateAdd

I'm trying to write a query that says "If [Type] = "Probationary Review 1" then add 14 days to [Employment Date]; "If [Type] = "Probationary Review 2" then add 3 months to [Employment Date]; "If [Type] = "Probationary Review 3" then add 5 months to [Employment Date] but I just can't get it and can't find anything to help me!
Oct 10 '11 #1
2 2068
ADezii
8,834 Expert 8TB
One approach would be to use a Recordset to perform the Conditional Updating of the [Employment Date] Field based on the Values in the [Type] Field. Assuming your Table is named tblData:
Expand|Select|Wrap|Line Numbers
  1. Dim MyDB As DAO.Database
  2. Dim rst As DAO.Recordset
  3. Dim dteNewDate As Date
  4.  
  5. Set MyDB = CurrentDb
  6. Set rst = MyDB.OpenRecordset("tblData", dbOpenDynaset)
  7.  
  8. With rst
  9.   Do While Not .EOF
  10.     Select Case ![Type]
  11.       Case "Probationary Review 1"          'Add 14 Days
  12.         dteNewDate = DateAdd("d", 14, ![Employment Date])
  13.       Case "Probationary Review 2"          'Add 3 Months
  14.         dteNewDate = DateAdd("m", 3, ![Employment Date])
  15.       Case "Probationary Review 3"          'Add 5 Months
  16.         dteNewDate = DateAdd("m", 5, ![Employment Date])
  17.       Case Else                             'None of the above, keep Date
  18.         dteNewDate = ![Employment Date]
  19.     End Select
  20.       .Edit
  21.         ![Employment Date] = dteNewDate
  22.       .Update
  23.         .MoveNext
  24.   Loop
  25. End With
  26.  
  27. rst.Close
  28. Set rst = Nothing
Oct 10 '11 #2
NeoPa
32,556 Expert Mod 16PB
Are you looking at a display query or an update query? Your question is unclear on this.

Can [Type] have any other values or are those three a closed list?
Oct 10 '11 #3

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

Similar topics

4
by: sah | last post by:
I need some help with the following query: DECLARE @SRV VARCHAR(20), @date smalldatetime SET @SRV = (select @@servername) SET @date = '20040901' select Srv_Name = @SRV, DB_Name = 'DB_NAME',...
1
by: Scott Sabo | last post by:
Hello- I have a query field called EmpHireDate. I want to be able to add a calculated field that will show the employee hire date plus 6 months. I can do this with DateAdd but I also need it...
2
by: rob | last post by:
Hello all, I have a report that is always due 14 weekdays (Monday thru Friday) from the day it is suspensed. I would like to use the DateAdd function using the weekday interval (...
15
by: CrostonScottish | last post by:
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...
33
by: =?Utf-8?B?RE9UTkVUR1VZ?= | last post by:
Hello, In vb.net there is a with statement, Is there are similar constructor in c#?
4
by: TimK65 | last post by:
Hello, I am doing something a little weird (I'm withholding the details only so I don't bore anyone, although if I can't find a way to do this with DATEADD, I will probably have to explain more...
3
by: ringer | last post by:
On a form I have a combo where a month is entered. It shows the month names in column one, but it is bound to column two where each month's corresponding number is, ie Jan=1, Feb=2, etc. So...
2
by: ncsthbell | last post by:
I am having problems getting the end date to calculate correctly. I start with Quarter '03/02', (YY/QTR), for this it means it is for the 2nd qtr of 2003. My goal is to get the begin & end dates...
8
missinglinq
by: missinglinq | last post by:
Here's a poser! Using Access 2003 SP2 The Control Source for txtMealDate is defined at table level as Date/Time. When this code is run Private Sub txtMealDate_AfterUpdate() ...
2
by: Organised Angel | last post by:
Hi everyone I'm doing a project at work and I'm managing most of it fine apart from one section where I need to calculate a due date. The due date is 5 working days after the date entered. I...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.