473,473 Members | 2,176 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Auto populate date field based on another date field

37 New Member
I want my "requalify date" to auto populate to the beginning of the month in the following year when my "liability date" gets entered/changed.

Example: Liablity date = 11/15/2010; 7/31/2011

Requalify date should be 11/1/2011; 7/1/2012

I am not sure how to write the formula to get this result.

The requalify date is a field in my main table as well as the liability date. When entering the formula, would entering it in the requalify date field's default value be the best.

Any help would be much appreciated. Thank you!

Yappy
Aug 3 '10 #1
9 8893
Steven Kogan
107 Recognized Expert New Member
Try using DateSerial(year, month, day) combined with DatePart(interval, date) to build your formula. The formula for requalify date can be:

DateSerial(DatePart("y",[Liability Date])+1,DatePart("m",[Liability Date]),1))
Aug 3 '10 #2
Steven Kogan
107 Recognized Expert New Member
Sorry, that should be:
DateSerial(DatePart("yyyy",[Liability Date])+1,DatePart("m",[Liability Date]),1)
Aug 3 '10 #3
yappy77
37 New Member
Hi, Steven!
Thanks for your reply. I do have another question since I am not sure if I am placing the expression in the correct area.

When entering the formula, would entering it in the requalify date field's default value be the best?

I have tried that and am getting errors.
Aug 4 '10 #4
Steven Kogan
107 Recognized Expert New Member
It could go in a query as a calculated field, or as the control source on the form.

Using it as a default value wouldn't work, as you've found out.

Did you want the value to be editable, or always based on a calculation? If you want it to be initially calculated after the liability date is entered, and then to be able to edit it after, you'd need to use VBA.

The code would be something like this:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Liability_Date_AfterUpdate()
  2.     If IsDate([Liability Date]) Then
  3.         [Requalify Date] = DateSerial(DatePart("yyyy", [Liability Date]) + 1, DatePart("m", [Liability Date]), 1)
  4.     End If
  5. End Sub
  6.  
Aug 4 '10 #5
NeoPa
32,556 Recognized Expert Moderator MVP
You will find it complicated to keep updating the value. Not impossible, but complicated.

This is not something you should really even be considering (See Normalisation and Table structures). A normalised database would calculate the related value as and when needed, but never store a value that can always be calculated reliably.
Aug 4 '10 #6
Steven Kogan
107 Recognized Expert New Member
I agree: if the value can always be calculated then it should not be a field in your table. If that's the case, add Requalify Date as a calculated field in a query. The exception would be if the database is for Access 2010, which supports calculated fields in tables.

The field in the query would be something like:

Expand|Select|Wrap|Line Numbers
  1. Requalify Date: DateSerial(DatePart("yyyy", [Liability Date]) + 1, DatePart("m", [Liability Date]), 1)
Aug 4 '10 #7
yappy77
37 New Member
Thank you so much! That is exactly what I needed. I tested it and it works perfectly.
Aug 4 '10 #8
NeoPa
32,556 Recognized Expert Moderator MVP
Steven,

you may want to check your PMs :)
Aug 4 '10 #9
Steven Kogan
107 Recognized Expert New Member
Hi NeoPa,

I'll be sure to include code in the [code] tags.

I'm unable to reply (regarding changing my status to Expert) with a PM. I haven't sent any, but I get the message:
Registered members under 50 posts can only send 3 private messages a day.
Aug 4 '10 #10

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

Similar topics

26
by: pb648174 | last post by:
I have a table called BidItem which has another table called BidAddendum related to it by foreign key. I have another table called BidFolder which is related to both BidItem and BidAddendum, based...
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...
13
by: pkinville | last post by:
ok, this is gonna seem stupid, but it has been stumping me all afternoon. I have two fields on a HTML page. HTML looks like this... <html> <head> <title>New Page 3</title> </head> <body>
2
by: Mike | last post by:
I'm sure this has been covered before in the newsgroup but have had no luck locating it. I have two tables: InstMonitors & MonModDesc Structure of MonModDesc: Model, Description Structure...
3
by: rmputnam | last post by:
I have a new patient table (PatTbl) that lists Acct, Last, First, among other fields. I need another table listing referring information (RefTbl). My goal is to enter the Acct number in the...
1
by: Neha Jain | last post by:
i have a table 'Tab1' with some fields. i want to create a screen consisting one of the fields in Table 'Tab1'.user must be able to select any of the data stored in the table for that field and any...
15
by: kpfunf | last post by:
I have one table of transactions, another table of price quotes. Transactions are nearly daily; quotes are periodic, roughly once per week. In a query, I want to pull the oldest (or least date)...
2
by: Ronald | last post by:
I hope somebody can help. I can't get into the specifics of my project, but I'll try to create a simple example: tblVehicle * VIN (text box) * Make (text box) * Model (text box) frmRepair
10
by: dkyadav80 | last post by:
<html> /// here what shoud be java script for: ->when script run then not display all input text field only display selection field. ->when user select other value for institute only this...
3
by: Cron | last post by:
Hi I'm trying to Dcount *unique* records by comparing a date/time field. I say *unique* because the field contains a date/time but I need to ignore the timestamp and work off the date only. I...
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...
1
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.