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

calculate the next date with a condition based on another field in the table

2
I have a field "x" with data : "3 and 4" for respective customers
I want the next date to be calculated for 1 year if the customer with x field is 4 and calculate 2 years if the field"x" is 3.

Right now to just calculate all the date with interbval of 1 year i have entered as
[LastTestDate]+364 but it calculates 1 year for all and does not satisfy the condition for customer with field x as 3
Dec 15 '15 #1
3 846
jforbes
1,107 Expert 1GB
A little more information will make it easer to answer this.
  • How are you calculating this, is it in a Query or is it in code on a Form?
  • Are you saving the calculated valve back into the Table?
  • Can you paste your actual code here so we can see it?
Dec 15 '15 #2
Apu91
2
I am saving this in Calculated valve back into the table

[LastTestDate]+364

I dont know how to proceed with calculating the next date with condition mentioned in my first post. Is it a good idea to perform in form? if so how?
Dec 15 '15 #3
jforbes
1,107 Expert 1GB
Whether you perform this in a Form or in a Query will depend on your process. Either will work.

Something like this is usually taken care of at the time the Date is entered or changed. So if you or your users are entering the LastTestDate on a Form, then it could be taken care of by code on the Form or a Data Macro if you are using Access 2010 or newer (a Data Macro is probably the best method). If you are using a routine to bulk import data then a Query is often used to update the field in Bulk.

Now to really throw a wrench into the works, I need to point out that it's rarely a good idea to save data that can be easily calculated. It's a common practice to create a query for this, and in this case an advantage is that if your rules change on how many years to add, you can change just the query and everything continues to work. This is a related article that might shed some light on this concept: https://bytes.com/topic/access/insig...ble-structures

So, in a Query, you can do something like this:
Expand|Select|Wrap|Line Numbers
  1. SELECT *, IIf([SomeField]=4,DateAdd('yyyy',1,[LastTestDate]),DateAdd('yyyy',2,[LastTestDate])) AS SomeImportantDate FROM SomeTable
To return the original table as well as the calculated field. The same idea would be used to update a table.

In a Form, when saving the date in the table, the code is similar and looks something like this:
Expand|Select|Wrap|Line Numbers
  1. Private Sub LastTestDate_AfterUpdate()
  2.     If Not Me!LastTestDate Is Null Then
  3.         If Me!SomeField = 4 Then
  4.             Me!SomeImportantDate = DateAdd("yyyy", 1, Me!LastTestDate)
  5.         Else
  6.             Me!SomeImportantDate = DateAdd("yyyy", 2, Me!LastTestDate)
  7.         End If
  8.     End If
  9. End Sub
Dec 15 '15 #4

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

Similar topics

6
by: jochen scheire | last post by:
Is there a way I can calculate a field in a form based on another field in the same form. When clicking submit, both values should be posted to the next page. I want to be able to type in a value...
6
by: Greg | last post by:
I am trying to change the value of one field in my query based on the value in another. If Field 1 had the text "ONACCNT" then in Feild 2 I want the date to change to today's date. Any help would...
1
by: Olly | last post by:
I need a date validation that will not allow a date to be entered in the field if it occurs before a date in another field (StartDate). But I cannot find any information on how to do this. Olly
0
by: Ray Holtz | last post by:
Is it possible to autofill a field based on what is entered into another field in a form? My form has an employee field, and department field. In an Items Table, I have fields FldEmployee, and...
11
by: Laery | last post by:
Hi, I'm currently adding a new module to an old borland C3.1 application (dos). And I need to calculate a date by subtracting the number of days from a given date. I know I could use an...
1
by: abprules | last post by:
Can somebody help me with this scenario? I want to update a date field when another field has a certain value entered. It is something like this: When the PDetType field ( from tlkpERegStatus...
8
by: ivijayan | last post by:
HI. I have the following query:- How do i create field which updates its contents on the basis of data in another field in same record. especially if I have a Date field, how can I change the...
7
by: simulationguy | last post by:
This is causing my some grief :) I have a form that displays records in a tabular format, one field is a combo box that displays values from another table. But I only want some of those values...
1
by: MadSma | last post by:
hi as i am a newbie to access i need some help for some basic functionality i need to be able to calculate a date after 6 or 12 months based on a staring date the user inputs on my form as well as...
11
by: mhschof | last post by:
I have an assigned SHIP DATE. I need to calculate an expected DUE date which is 9 working days prior to the ship date, and a START DATE which is 16 working days prior to the SHIP DATE. Working days...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.