473,385 Members | 1,400 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,385 software developers and data experts.

Using Code

Hez
Hi all,

I must admit, all I do in Access is puddle around. But I have been
searching for how I can correctly show age in a database I am making,
and have discovered, as Allen Browne says,
"These examples do not work reliably:
Format(Date() - DOB, "yyyy")
DateDiff("y", DOB, Date)
Int(DateDiff("d", DOB, Date)/365.25)"

And there is the code there ready to use, for the accurate version. So
here's my question....where do I put the code???
I know, a little knowledge is a dangerous thing!
Thanks in anticipation!

Nov 13 '05 #1
5 1233
Put the following in any module of your database:

=====================================
Function Age(varBirthDate As Variant)
Dim varAge As Variant

If IsNull(varBirthDate) Then Age = 0: Exit Function

varAge = DateDiff("yyyy", varBirthDate, Now)

If Date < DateSerial(Year(Now), Month (varBirthDate),
Day(varBirthDate)) Then
varAge = varAge - 1
End If
Age = varAge

End Function
====================================
Use the function in any expression in control sorces on your form/reports or
in queries. For example:
"=Age([MyDateField]"

-Ed
"Hez" <hm*****@swin.edu.au> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Hi all,

I must admit, all I do in Access is puddle around. But I have been
searching for how I can correctly show age in a database I am making,
and have discovered, as Allen Browne says,
"These examples do not work reliably:
Format(Date() - DOB, "yyyy")
DateDiff("y", DOB, Date)
Int(DateDiff("d", DOB, Date)/365.25)"

And there is the code there ready to use, for the accurate version. So
here's my question....where do I put the code???
I know, a little knowledge is a dangerous thing!
Thanks in anticipation!

Nov 13 '05 #2
Hez
Thanks Ed for your prompt reply and for the code. Not to be obtuse, are
you saying that I can copy the code and paste it into the 'exoression
builder" dialogue box of the control source area of the properties box
pertaining to the text box I want the answer to appear in??

Nov 13 '05 #3
Nope. Copy the code and paste it into a MODULE. Go to the database window
and select "module", then select any existing one or create a new one, then
paste the code into it. You now have a function (a code procedure that
returns a value) resident in memory whenever that database is open. You put
it to use by "calling the function". For example, on a form, create an
unbound text box and set its control source to:
=Age(MyBirthDateField]
Substitute the field name of the date field that contains DOB/birthdate/etc.
That form control will now display calculated age.
-Ed
"Hez" <hm*****@swin.edu.au> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Thanks Ed for your prompt reply and for the code. Not to be obtuse, are
you saying that I can copy the code and paste it into the 'exoression
builder" dialogue box of the control source area of the properties box
pertaining to the text box I want the answer to appear in??

Nov 13 '05 #4
Hez
Thanks Ed, got it now. Greatly appreciate your help.

Nov 13 '05 #5
Hez
Thanks Ed, got it now. Greatly appreciate your help.

Nov 13 '05 #6

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

Similar topics

0
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft...
17
by: beliavsky | last post by:
Many of my C++ programs have the line using namespace std; but the "Accelerated C++" book of Koenig and Moo has many examples where the library names are included one at a time, for example ...
12
by: Calum Grant | last post by:
In older C++ computer books, you'll often see using namespace std; even in my 1996 copy of Stroustrup. Nowadays, it seems to be considered better to qualify names to make it clearer what...
17
by: Danny J. Lesandrini | last post by:
The following code works with a standard MDB to navigate to a particluar record (with a DAO recordset, of course) but it's giving me problems in an ADP I'm working on. Dim rs As ADODB.Recordset...
13
by: Andrew | last post by:
I use conditional compiler constants, set through the VBA IDE in Tools, <projectname> Properties, that I refer to throughout my code to control which code is used during development, and which...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
1
by: Anonieko | last post by:
Understanding and Using Exceptions (this is a really long post...only read it if you (a) don't know what try/catch is OR (b) actually write catch(Exception ex) or catch{ }) The first thing I...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
2
by: lewisms | last post by:
Hello all, I am quite new to c++/. Net so please don't shoot me down for being a newbie. Any way I am trying to make a simple multithreading program that is just to learn the ideas behind it...
8
by: =?Utf-8?B?Q2hyaXMgSGFsY3Jvdw==?= | last post by:
Hi there I've successfully added some .NET validation controls to a page (using <asp:RequiredFieldValidator ...), however when I try to set the 'display' property to 'dynamic', my page then...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?

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.