Access coding datediff

  • Thread starter Thread starter San
  • Start date Start date
S

San

Hi I all!

I have a form information as name, address and so on, but I also have a
field with "Birthdate". I want to calculate the age from "Birthdate" to
(Now) and have it displayed in another field I haved called "Age".

I can do a little coding in excel and it does work there but in access
I don't have a single clue...well I mean I can make forms and stuff but
thats it.

appreciated any help

Thanks

San
 
Thx

But I don't even know where to type this :-\ And further more the
birthday field is (variable, I have many pages, one for each person in
the database)

My Birthday field is called "Birthday" And my age field is called "Age"

Birthday is of the type "Date" and Age is of the type "number"

many thx

San
 
First, you shouldn't have an Age field: you should be calculating it on the
fly each time you need it.

Create a query and put a computed field in it. If you're using the graphical
query builder, pick an empty column in the grid, and type the following into
the "Field" row of that column:

Age: DateDiff("yyyy", [Birthday], Date()) - IIf(Format(Date(), "mmdd") <
Format( [Birthday], "mmdd"), 1, 0)

There will likely be word-wrap in this post: what I've put above should be a
single line, starting with Age: and ending with , 0)

Use that query wherever you would otherwise have used the table.
 
Hi Douglas J. Steele


I have created at query with the table which contains the Birthday
calculation. And ind the designview of the query I have copied at
pasted the code into the "Field" row in an empty collum but then I get
the message:

"The expression you entered contains invalid syntax

You ommitted an operand or operator, you entered an invalid character
or comma, or or you entered a text without surrounding it with qutation
marks"

Thx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top