473,947 Members | 1,824 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Automatic age calculation

15 New Member
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.
Feb 25 '07 #1
13 14972
willakawill
1,646 Top Contributor
Hi. this is what microsoft has to say on this subject
Feb 25 '07 #2
Stephenoja
15 New Member
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.
Feb 25 '07 #3
willakawill
1,646 Top Contributor
You just need to put datediff on your form to calculate the age. The function, Now(), returns the system date and time.
Expand|Select|Wrap|Line Numbers
  1. DateDiff("y", #1-Feb-1995#, Now())
Feb 25 '07 #4
NDayave
92 New Member
I use this slightly longer code, but it returns the age as "15 Years 4 Months" for example.

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Public Function fnCalculateAge(strDateOfBirth As String)
  5.     Dim intYears As Integer
  6.     Dim intMonths As Integer
  7.     intYears = Year(Now) - Year(strDateOfBirth)
  8.     If Month(Now) < Month(strDateOfBirth) Or (Month(strDateOfBirth) = Month(Now) And Day(Now) < Day(strDateOfBirth)) Then
  9.         intYears = intYears - 1
  10.     End If
  11.     intMonths = Month(Now) - Month(strDateOfBirth)
  12.     If Day(Now) < Day(strDateOfBirth) Then
  13.         intMonths = intMonths - 1
  14.     End If
  15.     If intMonths < 0 Then
  16.         intMonths = intMonths + 12
  17.     End If
  18.     fnCalculateAge = intYears & " Years " & intMonths & " Months"
  19. 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
Feb 25 '07 #5
NeoPa
32,585 Recognized Expert Moderator MVP
Set the Control Source of the TextBox you want it displayed in to :
Expand|Select|Wrap|Line Numbers
  1. =Year(Date)-Year(Me!DateOfBirth)-IIf(Format(Date,"mmdd")<Format(Me!DateOfBirth,"mmdd"),1,0)
DateDiff("yyyy" ,,) returns the nearest whole number of years.
Feb 26 '07 #6
NeoPa
32,585 Recognized Expert Moderator MVP
Different versions can be supplied to handle months in the age as well if required.
Feb 26 '07 #7
NDayave
92 New Member
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
Feb 27 '07 #8
Rabbit
12,516 Recognized Expert Moderator MVP
Expand|Select|Wrap|Line Numbers
  1. (DateDiff("m", DOB, Date) \ 12) & " Years " & _
  2.    (DateDiff("m", DOB, Date) Mod 12) & " Months"
Feb 27 '07 #9
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.
Feb 27 '07 #10

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

Similar topics

8
4027
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...
0
2494
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...
2
3923
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...
4
3287
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...
4
3771
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:*....
5
6274
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.
3
3564
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>
17
2339
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...
3
4664
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.
0
1596
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...
0
10164
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, 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...
0
9983
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,...
0
11577
Oralloy
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...
0
10694
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 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...
0
9890
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, 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...
1
8256
isladogs
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...
0
6118
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...
0
6333
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3544
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 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...

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.