If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Access > Calculating age from date of birth

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-10-12, 05:47
cefndyengineering cefndyengineering is offline
Registered User
 
Join Date: Oct 2011
Location: Rhyl
Posts: 10
Calculating age from date of birth

Hi,

I have tried adding in people's ages from their date of birth. I've added a new text box into the form and named it age. I've added the following as the Control Source:

=DateDiff("yyyy",[Date of Birth],Now())+Int(Format(Now(),"mmdd")<Format([Date of Birth],"mmdd"))

This has worked perfectly, however when I try to scroll through the records, the following error message appears:
'The value you entered isn't valid for this field.
For example, you may have entered text in a numeric field or a number that is larger than the FieldSize permits.'

Please can anyone help? Thank you!
Reply With Quote
  #2 (permalink)  
Old 02-10-12, 08:21
MikeTheBike MikeTheBike is offline
Registered User
 
Join Date: Apr 2004
Location: Derbyshire, UK
Posts: 714
Hi

I would do it this way, if it helps
Code:
==DateDiff("yyyy",[DOB],Now())-IIf(Month(Now())<Month([DOB]),1,IIf(Month(Now())=Month([DOB]) And Day(Now())<Day([DOB]),1,0))
???

MTB

Last edited by MikeTheBike; 02-10-12 at 08:34. Reason: Corrected > to < (twice!)
Reply With Quote
  #3 (permalink)  
Old 02-12-12, 09:03
Missinglinq Missinglinq is offline
Registered User
 
Join Date: Jun 2005
Location: Richmond, Virginia USA
Posts: 1,702
Both formulas are valid so I expect the error is coming from something else.
  • Exactly how are you 'scrolling through Records?'
  • Is this a Single View Form (seeing one Record at a time)?
  • Does the Error appear immediately you start to scroll?
  • Is the [Date of Birth] Field defined as a Date/Time Datatype rather than Text?
I wonder if there is a Record which doesn't have a valid Date entered or perhaps one with nothing entered in the [Date of Birth] Field and the Error is popping when you reach this Record in your scroll.

Linq ;0)>
__________________
Hope this helps!

The Devil's in the Details!!

All posts/responses based on Access 2000/2003
Reply With Quote
  #4 (permalink)  
Old 02-13-12, 05:27
cefndyengineering cefndyengineering is offline
Registered User
 
Join Date: Oct 2011
Location: Rhyl
Posts: 10
Hello Missinglinq,

When I scroll through records using the 'Previous' or 'Next' command buttons, the error message does not appear, however when I scroll using the mouse scroll button, the error appears immediately after I scroll. It is in Single View Form, and I've changed the Date of Birth field to text, however this has not resolved the problem. All fields have got a valid Date entered.

Is there any way I could maybe prevent users from scrolling using the mouse scroll button?

Thanks!
Reply With Quote
  #5 (permalink)  
Old 02-13-12, 10:07
Missinglinq Missinglinq is offline
Registered User
 
Join Date: Jun 2005
Location: Richmond, Virginia USA
Posts: 1,702
Quote:
Originally Posted by cefndyengineering View Post
Hello Missinglinq,

When I scroll through records using the 'Previous' or 'Next' command buttons, the error message does not appear, however when I scroll using the mouse scroll button, the error appears immediately after I scroll. It is in Single View Form, and I've changed the Date of Birth field to text, however this has not resolved the problem. All fields have got a valid Date entered.

Is there any way I could maybe prevent users from scrolling using the mouse scroll button?

Thanks!
The Field should be defined as Date/Time; sometimes people define them as Text and that can lead to problems.

The Mouse Wheel has created havoc with Access apps since its invention, which is why for years many developers have disabled it, using a Stephen Lebans custom hack to do so. Microsoft finally addressed the issue with a native setting to do the same thing, with versions 2007/2010.

The best I can figure out, from yours as well as other posts I've seen over the years, scrolling the Records as rapidly as the wheel is capable of simply outstrips Access' ability to run the calculations and so an error is popped. The fact that the error doesn't really seem to address the problem at hand is not really surprising; Access error messages frequently don't!

Linq ;0)>
__________________
Hope this helps!

The Devil's in the Details!!

All posts/responses based on Access 2000/2003
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On