[RESOLVED] Whats the problem with this code????
i am using VBnet 2002 and crystal v9.1
Please I am trying to define an expression in my crystal report but still having errors , Can you help me please???
below is my code,please advice accordingly ;
VB Code:
Local StringVar message := "";
Local Datevar confdate ={pensioners.date_conf_pens_terms};
Local Datevar hiredate ={pensioners.hiredate};
if hiredate = confdate then
message="N/A"
ELSE
confdate
I simply want to display a message "N/A" on the report when dates are equal and confdate when otherwise.
Please help.
Re: Whats the problem with this code????
Maybe the dates stored in your database include a time portion as well which could be the reason your formula is not working as expected, eg if
{pensioners.date_conf_pens_terms} = 6/12/2006 19:01:21 and
{pensioners.hiredate} = 6/12/2006 19:01:20 then they would not be equal.
Your formula can return either a string or a date, so you would also need to convert the date to a string. You also don't need the message= bit....
Try doing this:
Code:
Local StringVar message := "";
Local Datevar confdate = Date({pensioners.date_conf_pens_terms});
Local Datevar hiredate = Date({pensioners.hiredate});
if hiredate = confdate then
"N/A" ' Get rid of message=
ELSE
CStr(confdate)
Re: Whats the problem with this code????
Thanks pete
I have tried your suggestion,the formula had no error...but the following are my observations;
Report only evaluates the first condition...(not after else)
cstr(confdate) doesnt display anything.... even if I pput it as the first condition
below is the code;
VB Code:
Local StringVar message := "";
Local Datevar confdate = Date({members.date_conf_pens_terms});
Local Datevar hiredate = Date({members.datehired});
if hiredate = confdate then
"N/A"
Else
cstr(confdate)
please help
Re: Whats the problem with this code????
Could it be that there are some records with Null dates in these fields? Nulls can play havoc with Crystal if you're not aware of them. Try this:
Open your report in Crystal, go to the File menu and select Report Options. Check the box labelled Convert Database NULL Values to Default.
One question, why are you storing your values in variables in the formula? There's really no need, why not just do this...
VB Code:
If {members.date_conf_pens_terms} = {members.datehired} Then
"N/A"
Else
cstr({members.date_conf_pens_terms})
Re: Whats the problem with this code????
Thanks very much it is now working!!!!!!!!!!