Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I just wanted to say THANKS for the forum. The knowledge I gain from your site is invaluable..."

Geography

Where in the world do Tek-Tips members come from?
RenaG (Programmer)
12 Mar 12 14:07
I am using Crystal 10.

How would you calculate a date range if given the request:

Quote:

I want a report of all males between 18 - 50 years of age.

TIA,
~RLG
 
Helpful Member!  lbass (TechnicalUser)
12 Mar 12 15:04
Create a formula {@age} as shown here: http://www.kenhamady.com/form06.shtml
and then use a record selection formula like:

{table.gender} = "M" and
{@age} in 18 to 50

-LB
RenaG (Programmer)
12 Mar 12 15:42
Hi LB,

That got me started but I have run into a hiccup.  I added the code on Ken Hamandy's page in the @age function using

CODE

DateVar Birth := Date({Patient.Birth_DtTm});
DateVar Ann := CurrentDate;

I placed this Formula on the report and it seems to be calculating correctly and sees it as a number.

But when I reference it in the record selection formula like this:
@age in (18.00 to 50.00)

It says there is an error in the formula:

Quote:

A number, currency amount, boolean, date, time, date-time, or string is expected here
I have tried several ways of asking this question, such as:
@age >= 18 and @age <= 50
And they all get the same error message. When I mouse over it on the report is says it is a number so I don't understand why it gives this error.  Any suggestions?

TIA,
~RLG
 
lbass (TechnicalUser)
12 Mar 12 20:28
You are not showing the entire formula from Ken's page. Please show the actual formula you used for {@age} if it contained more that what you are showing above.

-LB
RenaG (Programmer)
13 Mar 12 10:09
Good morning!

Here is the entire formula:

CODE

WhileReadingRecords;
DateVar Birth:= Date({Patient.Birth_DtTm});   // Replace this with your field for Date Of Birth
DateVar Ann := CurrentDate;  // Replace this with CurrentDate to get their age as of the time of the report
  //or the date field of an event to get their age as of the time of that event.
if (Month(Ann) * 100) + Day (Ann) >=(Month(Birth) *100) + Day (Birth)  
then Year (Ann) - Year(Birth)  
else Year (Ann) - Year(Birth) -1

Did I miss anything?

~RLG
 
lbass (TechnicalUser)
13 Mar 12 12:58

Just noticed that you didn't use square brackets, but you don't need any at all:

@age in 18 to 50

And you don't need decimals, since the result is always a whole number. If you did want to use brackets, it would be:

@age in [18 to 50]

-LB
 
 
RenaG (Programmer)
13 Mar 12 13:11
Argh! I just figured out what was wrong.  I did not have the curly braces around @age! So at least I can save it.  Now to test it to see if it works!

Thanks for all your help!

~RLG
 

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close