473,320 Members | 2,104 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,320 software developers and data experts.

VBA in calculated date field

Dear knowledgeable folks,

System: Windows XP and Access 2002.
In my participants form, I have the following date fields:
EnrollmentDate: the actual date that the participant officially began
the program
ActualExitDate: the actual date that the participant exited the
program
MaximumDate: =[EnrollmentDate]+547 547 days added to the
EnrollmentDate, which is the maximum amount of time (18 months) that a
person can be enrolled in the program
LengthDate: =(Date()-[EnrollmentDate])/30 calculates the number of
months that the participant has actually been enrolled in the program

What I need now is some VBA code that will do the following in the
LengthDate text box:

IF ActualExitDate is null,
then LengthDate = (Date()-[EnrollmentDate])/30,
otherwise LengthDate = (ActualExitDate - EnrollmentDate)/30),

Also, once I figure out the correct VBA code, do I enter it under "On
Update" or "After Update" or where??????
Thanks a bunch.
- Ken -

Nov 13 '05 #1
2 2157
You'll have to provide more information regarding when you want the
field to be calculated (button click, form closing, etc.)

Also, consider using an expression in a query to do the calculation.
It saves you from actually storing the calculated result in the
database, and having to update it every time the underlying data
changes.

Nov 13 '05 #2
Dear Sir,
Have you looked at DateAdd() and DateDiff() in the help files? These may do
what you want. If not that, then a scalar function to do the math might
work. At the ugliest, parsing the date into its component pieces and then
doing the math would also work. But parsing the date requires API calls to
Windows to find out what the localization settings are so you can interpret
the date correctly.
--
Alan Webb
kn*******@SPAMhotmail.com
"It's not IT, it's IS"

<ms******@tongaken.org> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Dear knowledgeable folks,

System: Windows XP and Access 2002.
In my participants form, I have the following date fields:
EnrollmentDate: the actual date that the participant officially began
the program
ActualExitDate: the actual date that the participant exited the
program
MaximumDate: =[EnrollmentDate]+547 547 days added to the
EnrollmentDate, which is the maximum amount of time (18 months) that a
person can be enrolled in the program
LengthDate: =(Date()-[EnrollmentDate])/30 calculates the number of
months that the participant has actually been enrolled in the program

What I need now is some VBA code that will do the following in the
LengthDate text box:

IF ActualExitDate is null,
then LengthDate = (Date()-[EnrollmentDate])/30,
otherwise LengthDate = (ActualExitDate - EnrollmentDate)/30),

Also, once I figure out the correct VBA code, do I enter it under "On
Update" or "After Update" or where??????
Thanks a bunch.
- Ken -

Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Miguelito Bain | last post by:
hi everybody. i'm trying to find out what you can and can't do with/in calculated fields. any help, pointers, and/or advice would be greatly appreciated. i'm a newbie, but i want to learn, and...
1
by: douh | last post by:
I know that this is not the way, however I need to save certian calculated values so that they do not change over time, ie. new tax rates etc. This is for an invoice header and invoice subform. I...
1
by: Norbert Lieckfeldt | last post by:
MS Access 2002 here. I am just trying to set up a simple database for a friend who's an optician. Basically, all clients with address details, date of last eyetest and a drop-down combo box to...
2
by: Norbert Lieckfeldt | last post by:
I am setting up a database for a friend who's an Optician, using MS Access 2002. All seems to be working well, but I have hit a snag. There's a calculated field both in a form and a query which...
5
by: paulquinlan100 | last post by:
Hi Can anyone spot an obvious problem with the following calculated field on a report. Im trying to use the field only when it contains data (which it normally doesnt) =(DateDiff("d",(IIf(...
4
by: john | last post by:
I've searched google but can't find what I need. In my form I have a field Date Of Birth. Netxt to that field I would like to put a calculated field that shows the age of that particular person,...
2
by: EdDale | last post by:
Hi and thanks in advance, I am using DMin and DMax to calculate date fields in a form. I need to use these calculated dates in another calculated field. example: =DMax("","B&MPayPeriod"," >=...
2
by: jcf378 | last post by:
hi all. I have a form which contains a calculated control ("days") that outputs the # of days between two dates (DateDiff command between the fields and ). However, when I click "Filter by...
3
by: Ciara9 | last post by:
I am having problems trying to update a field in a database using a field in a form. I currently have two fields, Today and Tomorrow in a table named Date. The Today field automatically defaults to...
6
by: Steve67 | last post by:
Wonder if I can get someone’s help with a problem I am having on where to place an IF statement in VBE. I have created a form in Access 2003 that has an automatic calculated field. Basically you...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.