Hello guys,
Thanks for all the help with the last question. I have another one. Does anyone know how to let access automatically calculate age and display in field when the person's date of birth is entered? Is that even possible? Any help would be greatly appreciated. Thanks.
13 14972
Hi. this is what microsoft has to say on this subject
Hi. this is what microsoft has to say on this subject
Thank you Willa, I checked the site but what I actually want to do is to calculate the persons's age based on the computer system's date. So I will enter the person's birthday and access should use the system's date to calculate and display the person's age in years. Am not sure if this is possible but am still reading through some materials. Thanks again.
You just need to put datediff on your form to calculate the age. The function, Now(), returns the system date and time. - DateDiff("y", #1-Feb-1995#, Now())
I use this slightly longer code, but it returns the age as "15 Years 4 Months" for example. - Option Compare Database
-
Option Explicit
-
-
Public Function fnCalculateAge(strDateOfBirth As String)
-
Dim intYears As Integer
-
Dim intMonths As Integer
-
intYears = Year(Now) - Year(strDateOfBirth)
-
If Month(Now) < Month(strDateOfBirth) Or (Month(strDateOfBirth) = Month(Now) And Day(Now) < Day(strDateOfBirth)) Then
-
intYears = intYears - 1
-
End If
-
intMonths = Month(Now) - Month(strDateOfBirth)
-
If Day(Now) < Day(strDateOfBirth) Then
-
intMonths = intMonths - 1
-
End If
-
If intMonths < 0 Then
-
intMonths = intMonths + 12
-
End If
-
fnCalculateAge = intYears & " Years " & intMonths & " Months"
-
End Function
Use as a module, and enter "=fnCalculateAg e([Name of Text box with Date of Birth in])" in the text box on the form you want to display the age.
Obviously you need the Date of Birth text box on the form, but it can be invisible.
This may not be what you were looking for, but i thought id give you another option on the format of the Age calculated.
NDayave
NeoPa 32,585
Recognized Expert Moderator MVP
Set the Control Source of the TextBox you want it displayed in to : - =Year(Date)-Year(Me!DateOfBirth)-IIf(Format(Date,"mmdd")<Format(Me!DateOfBirth,"mmdd"),1,0)
DateDiff("yyyy" ,,) returns the nearest whole number of years.
NeoPa 32,585
Recognized Expert Moderator MVP
Different versions can be supplied to handle months in the age as well if required.
Different versions can be supplied to handle months in the age as well if required.
How would you display it as Years and Months using the DateDiff?
Im guessing it would be shorter than my code, which is always a bonus
NDayave
Rabbit 12,516
Recognized Expert Moderator MVP - (DateDiff("m", DOB, Date) \ 12) & " Years " & _
-
(DateDiff("m", DOB, Date) Mod 12) & " Months"
NeoPa 32,585
Recognized Expert Moderator MVP
That will work for the nearest value, which is probably more acceptable when measuring in months than in simple years, rather than whole months.
DateDiff() will always round to the nearest, rather than work in whole integer values.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Aspersion |
last post by:
I'm building an ASP page that has a lot of text and graphics.
There is a calculation facility on the page. The user enters several
numbers in a form and presses a button to see the calculated answer.
The problem is this: when the user presses the Calculate button, the
whole page is reloaded and, on a large page, this is very noticeable.
Is there any way that I can get the calculation done and the result
displayed without reloading...
|
by: anaxamandr |
last post by:
Hi.
I have a long loop in ASP that performs a rather lengthy calculation. I would love for my users to be able to stop that calculation, if they so choose, mid way through the process.
I attempted to use a parent window that allows the user to launch the calculation in a seperate window, so that they could still click "stop" to write a value to a database or set a session level variable that the calculation would check to see if it should...
|
by: Del |
last post by:
Thanks in advance for any help.
I have a database that was created in Access 2000. Several users have
been upgraded to Access 2003. Since upgrading to 2003 we have noticed
that some of the calculated fields are not being populated. The
database is a samll invoicing database on the form and report we have
columns call Unit Cost. This is the actual cost of the part and is
pulled from our parts master table and is displayed in a sub form...
|
by: Michiel Alsters |
last post by:
Hello everybody,
I hope anybody can help me. I'll try to give a brief overview of my
problem. I have running a program that performs a heavy calculation.
To give the user feedback what the program is doing I show a window
which contains a progress bar and a label. At some point during the
execution the state of the calculation is changed, so I want to let
the user know this.
I have placed the creation of the form in a seperate thread...
|
by: vg-mail |
last post by:
Hello all,
I have identical design for form and report but I am getting
calculation error on form and everything is OK on report. The form and
report are build up on SQL statement. The calculation is very simple.
The calculation is done in an underling query if I can call it a query
or I should call it a SQL statement. It looks like a query but it is
not saved as the query. The calculation in that query is very simple -
ExtendedPrice:*....
| |
by: The alMIGHTY N |
last post by:
Hi all,
Let's say I have a simple math formula:
sum (x * y / 1000) / (sum z / 1000)
I have to do this across 50 items, each with an x, y and z value, when
the page first loads AND when a user modifies any of the x, y and z
values.
|
by: mattmao |
last post by:
Okay, I was asked by a friend about the result of this limit:
http://bbs.newwise.com/attdata/forumid_14/20070922_fe7f77c81050413a20fbDWYOGm7zeRj3.jpg
Not n->zero but n-> + infinite
I really know nothing about advanced math, so I wrote a C program to help me:
(BTW, I guess the result would be ln2.)
#include <stdio.h>
|
by: Sunburned Surveyor |
last post by:
I was thinking of a way I could make writing Python Class Files a
little less painful. I was considering a Ptyhon script that read a
file with a list of property names and method names and then generated
a skeleton class file.
I was even thinking of automatically generating the shell for doc
strings and epydoc tags.
Is there existing scripts that do something like this? If not, I will
try to come up with something. If I'm sucessful...
|
by: myjish18 |
last post by:
Hello,
We have a DB2 UDB database v8.2.7 (db2 v8.2 fixpak 14) on AIX 5.3
which has Automatic Storage (AS) enabled. We want to disable
automatic storage on entire database and/or disable automatic storage
on all tablespaces. DB2 Manual says it once AS is enabled, it cant be
changed. Is there any way to disable the AS or any other alternative?
Please advice.
|
by: vamsioracle |
last post by:
Hi all
I have a disco Report with two sheets. In sheet 1, i used a function from database that inserts data (based on some calculation) into a table. In sheet 2, the column inserted by function in sheet1 is to be displayed. Is it possible to dynamically display this, If the calculation changes in sheet and inserts thee data, will i be able to see that in sheet two immediately after i do refresh.
I tried this, but not working. I have to...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |