Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

After DateAdd function values do not sort as dates

Status
Not open for further replies.

kstearns04

Programmer
Oct 23, 2001
4
US
I have an Access DB which stores a Week Ending value as a number. I have created a report which needs the actual Week Ending Date which calculates fine (WeekEndingDt: IIf(([WEEKENDING]=0),"",DateAdd("ww",[WEEKENDING],"12/31/89")), however when I sort, I get January, October, November, December, February, and so on. It appears that the calculation is seen as a text format, not date format. I am actually trying to use a Between...And to pull specific date ranges but I get incorrect data unless the date range is for February through September! Is there a way to force a date data type within the recordsource of my report or some other solution to this problem? Thank you for any help possible!
 
Many / most / all of the "dat" functions return either string or (more commonly) variant data types. to get back to date type , "Wrap" the date add in a CDate:

IIf(([WEEKENDING]=0),"",CDate(DateAdd("ww",[WEEKENDING],"12/31/89")))

or thereabouts



MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Thanks for the info! I ended up using a format command on the field

WEEKENDINGDT: IIf(([WEEKENDING]=0),"",Format(DateAdd("ww",[WEEKENDING],"12/31/89"),"yyyy/mm/dd")

and the Between...And statement

Between Format([Forms]![frmBeginEndDates]![BeginningDate],"yyyy/mm/dd") And Format([Forms]![frmBeginEndDates]![EndingDate],"yyyy/mm/dd")

And it worked also. CDate will be easier in the future I think!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top