473,395 Members | 1,938 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.

Auto Calculate and Populate Date Field

I am working with a database now and need some guidance.

I am attempting to input an auto calculation. I have the ability to enter a date in a text box on a form. I want to be able to have another field that auto calcuates 90 days later and simiply displays that date. The auto calculated date does NOT have to be assiocated with a field in any table, just a caculation in what I believe would be referred to an unbounded box.

For example, I would enter 1/1/2008 and when I tab to the next field a calculation would occur below it in a box that would show a date 90 days later. (4/1/2008)

Any suggestions?

Thanks,
Adam
Feb 25 '08 #1
6 12390
I was able to figure out the correct coding:

=DateSerial(Year([CaseResolvedDate]),Month([CaseResolvedDate]),Day([CaseResolvedDate])+90)

However, I still need help...when there is no date entered into the CaseResolvedDate field "#error" is displayed. How can I hide that error message and only allow a date message to be displayed?
Feb 25 '08 #2
JustJim
407 Expert 256MB
I was able to figure out the correct coding:

=DateSerial(Year([CaseResolvedDate]),Month([CaseResolvedDate]),Day([CaseResolvedDate])+90)

However, I still need help...when there is no date entered into the CaseResolvedDate field "#error" is displayed. How can I hide that error message and only allow a date message to be displayed?
Hi,

Try looking at the help file for the DateAdd function, I think you will find it easier to use.

I don't know if that will stop your #ERROR problem though.

Jim
Feb 25 '08 #3
missinglinq
3,532 Expert 2GB
Several things. I assume from

=DateSerial(Year([CaseResolvedDate]),Month([CaseResolvedDate]),Day([CaseResolvedDate])+90)

that you're using this code in the Control Source for your unbound textbox. This means that when the record is created, Access tries to run the calculation, but at this point CaseResolvedDate is null, because it has no data in it. So you need to move this calculation to the AfterUpdate event of CaseResolvedDate. Since your second textbox is unbound, you'll also have to re-calculate each time you move back to a record. For the purpose of this example I've called the unbound textbox Plus90TextBox.

Next, Access has a function designed specifically for adding to dates, called DateAdd(), so we'll use that here.
Expand|Select|Wrap|Line Numbers
  1. Private Sub CaseResolvedDate_AfterUpdate()
  2.   Me.Plus90TextBox = DateAdd("d", 90, Me.CaseResolvedDate)
  3. End Sub
  4.  
  5. Private Sub Form_Current()
  6.   Me.Plus90TextBox = DateAdd("d", 90, Me.CaseResolvedDate)
  7. End Sub
  8.  
The last thing is that adding 90 days to your original CaseResolvedDate of 1/1/2008 will not get you 4/1/2008, it'll yield 3/31/2008. So if you want 3/31/2008 the above code will work. If you actually want 1/1/2008 to yield 4/1/2008, you need to add 3 months instead of 90 days, and use this code instead.

Expand|Select|Wrap|Line Numbers
  1. Private Sub CaseResolvedDate_AfterUpdate()
  2.   Me.Plus90TextBox = DateAdd("m", 3, Me.CaseResolvedDate)
  3. End Sub
  4.  
  5. Private Sub Form_Current()
  6.   Me.Plus90TextBox = DateAdd("m", 3, Me.CaseResolvedDate)
  7. End Sub
  8.  
Linq ;0)>
Feb 25 '08 #4
missinglinq-

Thanks so much for your help! What a quick response. I copied your first set of VB code and it worked perfect. I was looking for 90 days, not 3 months so the 90 day date was perfect.

I really appreciate your help!

Adam
Feb 25 '08 #5
NeoPa
32,556 Expert Mod 16PB
Another possible way to handle Null values is as follows :
Expand|Select|Wrap|Line Numbers
  1. =Iif(IsNull([CaseResolvedDate]),Null,DateAdd("d", 90, [CaseResolvedDate]))
I have to say I rather like Linq's solution though.
Feb 26 '08 #6
missinglinq
3,532 Expert 2GB
You know my signature, Ade:

"There's Always more than one way to skin a cat!"

;0)>
Feb 26 '08 #7

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

Similar topics

8
by: Alistair | last post by:
this has been driving me nuts for over an hour now. I have a DB with a date field that is empty Because of this the records sometimes get included in searches because their contents are less...
1
by: Liz Malcolm | last post by:
Hello and TIA. I have a DE form with an option group that if daily is selected todays date is used for start and end date, if weekly is selected Monday - Friday is used. I am trying to add a...
2
by: buck | last post by:
I'm working on a helpdesk database - does anyone know how to auto enter the date in a new record; would it be soemthing like iif field is null auto enter?
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: kunal0101 | last post by:
Hi, I am a new user to access and am building a database to capture the rotation dates for employees. There is a table called "Rotation schedule" which contains "name", "Duration (in weeks) and...
7
by: sheri | last post by:
I have a field called date, the date is in the field like this 70925 (which means Sept. 25, 2007). I have another field called day, it is a text field. How do I write a query to populate the day...
4
by: whamo | last post by:
I have the need to populate a field based on the selection in a combo box. Starting out simple. (2) tables tbl_OSE_Info and tbl_Input; tbl_OSE_Info has three fields: Key, OSE_Name and OSE_Wt...
2
by: viporyo | last post by:
I'm creating an Access Database 2003 for our Human Resource Dept. In the form, I will be adding a calendar wherein there will be date of hire, start date, etc. I need to be able to view the...
9
by: yappy77 | last post by:
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 ...
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
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
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...
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.