igendreau wrote:
[color=blue]
> Hey Tim, what does the "d" do in your code?
>
> I copied and pasted your string exactly, then substituded
> [WO_REQUEST_DATE] for [BookingDate] which is my date field. I created
> a new query based on my table, and posted this to create a new
> calculated field. It immediately gives me an error saying I have
> invalid syntax, and when I hit "Okay" it highlights the "d". Here's my
> code:
>
> Projected_Date: Switch(DateDiff("d",[BookingDate],Date())<=30,"0-30
> Days Out",DateDiff("d",[BookingDate],Date())<=60,"31-60 Days
> Out",DateDiff("d",[BookingDate],Date())<=90,"61 to 90
> Days",DateDiff("d",[BookingDate],Date())>90,"Over 90 Days Out")[/color]
The "d" is the argument for the datediff function (not sure what version
of Access you're using but you can look this up in help). You say you
pasted it exactly, so, hopefully you haven't removed any qutation marks
that are in the switch expression.
Another thing to be aware of is to make sure any line breaks from
pasting the code are removed. I just copy and pasted from my news
reader your reply message and my first results only gave me "0-30"
instead of "0-30 Days Out". I got rid of the line breaks and everything
went tickity boo! 8)
An easy way of doing this is pasting the code in Word and removing line
breaks and then copying and pasting into the query design grid.
The other thing to be certain of - is BookingDate a date field? Stupid
question and I'm not trying to insult your intelligence, but it's easy
to overlook the easy things sometimes... 8)
Anther thing - did you paste this into the SQL view or the query design
grid? The expression is designed to be pasted into the design grid. If
you want to put it directly into SQL, then you'd place the following
after a comma in the select clause:
Switch(DateDiff("d",[BookingDate],Date())<=30,"0-30 Days
Out",DateDiff("d",[BookingDate],Date())<=60,"31-60 Days
Out",DateDiff("d",[BookingDate],Date())<=90,"61 to 90
Days",DateDiff("d",[BookingDate],Date())>90,"Over 90 Days Out") as
Projected_Date
--
Tim
http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me