What's wrong with DateAdd

  • Thread starter Thread starter sara
  • Start date Start date
S

sara

I am getting "Type Mismatch in Expression" in my query.
What am I doing wrong here? I need to find a data 90 days
earlier than a date a user enters as a parameter.

DateAdd("d",-90,[SaleDate])

Also tried DateAdd("m",-3,[SalesDate])

Is this allowed in Access? How can I get my date?
Thanks
 
What is SaleDate? Looks like Accesss does not recognise it as a date.

If it is a Text type field in a table, or a calculated date in a query, try:
DateAdd("d",-90,CVDate([SaleDate]))
 
I am getting "Type Mismatch in Expression" in my query.
What am I doing wrong here? I need to find a data 90 days
earlier than a date a user enters as a parameter.

DateAdd("d",-90,[SaleDate])

Also tried DateAdd("m",-3,[SalesDate])

Is this allowed in Access? How can I get my date?
Thanks

I assume [SaleDate] is your parameter prompt.
The criteria you are using will return records just for the one date
that is exactly 90 days earlier.
Are you sure you have records for just that one date?
Do your records include a time value as well as the Date value?
If so, only records with a time value of Midnite will be returned if
you use the above functions.

Perhaps try < DateAdd("d",-90,[SaleDate])
or try > DateAdd("d",-90,[SaleDate])
to see if any records are returned.

or if you do need just that one day, use:
between DateAdd("d",-90,[SaleDate]) and DateAdd("d",-89,[SaleDate])
 
Thanks. I tried < and > and both got: "The expression you
entered contains invalid syntax".

I changed it to -1, just in case it was a data problem,
and still get type mismatch. Also, I get the error so
fast, it's not "compiling" is my guess. SaleDate is the
parameter, or I thought I'd do "Now()" and save the user
from putting in a date. When I put in [Enter Date] I
still immediately get the "Type Mismatch" which is why I
say the "compile" problem.

SaleDate in the table is just the date mm/dd/2004. And I
put in the format of "ShortDate" just in case. It's still
not working. I am looking for the exact date of 90 days
earlier, as then I will look for records between Today and
90 days ago and count certain criteria in them.

Very frustrating.
Thanks for your help.
Sara

-----Original Message-----
I am getting "Type Mismatch in Expression" in my query.
What am I doing wrong here? I need to find a data 90 days
earlier than a date a user enters as a parameter.

DateAdd("d",-90,[SaleDate])

Also tried DateAdd("m",-3,[SalesDate])

Is this allowed in Access? How can I get my date?
Thanks

I assume [SaleDate] is your parameter prompt.
The criteria you are using will return records just for the one date
that is exactly 90 days earlier.
Are you sure you have records for just that one date?
Do your records include a time value as well as the Date value?
If so, only records with a time value of Midnite will be returned if
you use the above functions.

Perhaps try < DateAdd("d",-90,[SaleDate])
or try > DateAdd("d",-90,[SaleDate])
to see if any records are returned.

or if you do need just that one day, use:
between DateAdd("d",-90,[SaleDate]) and DateAdd("d",-89, [SaleDate])
--
Fred
Please only reply to this newsgroup.
I do not reply to personal email.
.
 
Thank you. I tried your code (and the other suggestions)
and I still get the Type Mismatch error. SaleDate is the
field from my table, and it is a date. I have also
formatted it in the query as shortdate, and in the table
the data is mm/dd/2004.

Any further thoughts?
Thanks.
Sara

-----Original Message-----
What is SaleDate? Looks like Accesss does not recognise it as a date.

If it is a Text type field in a table, or a calculated date in a query, try:
DateAdd("d",-90,CVDate([SaleDate]))

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

I am getting "Type Mismatch in Expression" in my query.
What am I doing wrong here? I need to find a data 90 days
earlier than a date a user enters as a parameter.

DateAdd("d",-90,[SaleDate])

Also tried DateAdd("m",-3,[SalesDate])

Is this allowed in Access? How can I get my date?
Thanks


.
 
Sara, if SaleDate is a Date/Time field in a query, then there has to be
something else going on.

Are you using criteria under the calculated field?

Is the query doing any aggegation (e.g. GROUP BY)?

Switch the query to SQL View (View menu), and post the entire SQL statement
here.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

sara said:
Thank you. I tried your code (and the other suggestions)
and I still get the Type Mismatch error. SaleDate is the
field from my table, and it is a date. I have also
formatted it in the query as shortdate, and in the table
the data is mm/dd/2004.

Any further thoughts?
Thanks.
Sara

-----Original Message-----
What is SaleDate? Looks like Accesss does not recognise it as a date.

If it is a Text type field in a table, or a calculated date in a query, try:
DateAdd("d",-90,CVDate([SaleDate]))

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

I am getting "Type Mismatch in Expression" in my query.
What am I doing wrong here? I need to find a data 90 days
earlier than a date a user enters as a parameter.

DateAdd("d",-90,[SaleDate])

Also tried DateAdd("m",-3,[SalesDate])

Is this allowed in Access? How can I get my date?
Thanks


.
 
Thanks. I tried < and > and both got: "The expression you
entered contains invalid syntax".

I changed it to -1, just in case it was a data problem,
and still get type mismatch. Also, I get the error so
fast, it's not "compiling" is my guess. SaleDate is the
parameter, or I thought I'd do "Now()" and save the user
from putting in a date. When I put in [Enter Date] I
still immediately get the "Type Mismatch" which is why I
say the "compile" problem.

SaleDate in the table is just the date mm/dd/2004. And I
put in the format of "ShortDate" just in case. It's still
not working. I am looking for the exact date of 90 days
earlier, as then I will look for records between Today and
90 days ago and count certain criteria in them.

Very frustrating.
Thanks for your help.
Sara
** snipped **

You have me totaly confused now.
You wrote that [SaleDate] is your parameter, and then you write that
[SaleDate] is a field in your table.
I'm confused and I'm sure Access is also.
Is [SaleDate] a valid Date Datatype? Or is it a Text Datatype field?
And I still don't know if the [SaleDate] field includes a time value
or not.
Try this:
Change the query criteria for the [SaleDate] field to:

Between DateAdd("d",-90,[Enter a Date]) and DateAdd("d",-89,
[Enter a Date])

You will be prompted just once to enter one date.
Enter the date in US date format
Month/day/year.
Do you get a record exactly 90 days old from that date (assuming there
is at least one)?
If you still have difficulty, post the entire query SQL.
 
Great! I'm making some great progress here.
First, SaleDate is in the table, but I was asking the User
to Enter the date to choose the 90 day period. (The LP
person isn't always in the office, and may need to run the
report on one day, for many prior days. I'll work on that
efficiency later - first I just wanted to get the data).
So that's why it seemed to be both a parameter and in the
table.

I was using 2 columns, and your code here pointed me to
put the "Between" in the same way I'd put plain old [Enter
Date]. This worked - BUT
I put in -26 and -27 since I only have data from 1/3/04.
With a parameter of 2/1/04, I got 2 days selected 1/6 and
1/7, not one date as you expected. HOWEVER, this is good!
I actually want ALL the records (can have one per cashier
per store per day), where the cashier was off + or - $5.00
or more. So, I changed it to -30 and just [Enter Date] in
the code and I get all the records where the cashier is
either +4.99 or -4.99 or more. Once all this works, I'll
load the earlier data so I can do -90 as LP needs.

That is the first step, and the end of the good news.
Now, I put in "Count(*) >1" under the Cashier column. And
I only get one date (1/27/04) and only one record per
cashier, when each of the 3 displayed have at least 2 days
with the problem I'm looking to display. And I'm not
getting the other cashiers who have more than 1 day of
having +/- $5 in the time period.

Here is the code:

SELECT [T: Cashier OverShort].SALEDATE, [Static Store
Info].StoreName, [T: Cashier OverShort].Cashier, [T:
Cashier OverShort].LastName, [T: Cashier
OverShort].FirstName, [T: Cashier OverShort].OverShort
FROM [T: Cashier OverShort] INNER JOIN [Static Store Info]
ON [T: Cashier OverShort].STNum = [Static Store Info].StNum
GROUP BY [T: Cashier OverShort].SALEDATE, [Static Store
Info].StoreName, [T: Cashier OverShort].Cashier, [T:
Cashier OverShort].LastName, [T: Cashier
OverShort].FirstName, [T: Cashier OverShort].OverShort,
[T: Cashier OverShort].Cashier, [T: Cashier
OverShort].STNum, [T: Cashier OverShort].OverShort
HAVING ((([T: Cashier OverShort].SALEDATE) Between DateAdd
("d",-30,[EnterDate]) And [EnterDate]) AND (([T: Cashier
OverShort].OverShort)>4.99 Or ([T: Cashier
OverShort].OverShort)<-4.99) AND (Count(*)>1))
ORDER BY [T: Cashier OverShort].SALEDATE, [T: Cashier
OverShort].LastName, [T: Cashier OverShort].STNum;


Sample Data: (Just Date, Store, Cashier, OverShort)
1/15 Lynn 5703 (10.00)
1/20 Lynn 5703 10.63
1/17 Swansea 11207 (6.11)
1/4 Swansea 11207 (9.93)
1/27 Worcester 12513 (10.00)
1/27 Lynn 15318 (9.90)
1/27 Norwood 16228 (64.46)
1/30 Worcester 12513 (10.29)
1/3 Cranston 2334 (27.92)
1/3 Cranston 2482 18.44
1/3 Somerville 2287 9.91

With the code above, I only get the 3 1/27 records, and
not the 1/15 and 1/20 for 5703, or 1/17 and 1/4 for 11207.

ALSO, 15318 and 16228 have only 1 error in the time
period, so I don't know why they were selected.

I am stumped, and, again, ask for (and so greatly
appreciate) your help.
Sara



-----Original Message-----
** snipped **

You have me totaly confused now.
You wrote that [SaleDate] is your parameter, and then you write that
[SaleDate] is a field in your table.
I'm confused and I'm sure Access is also.
Is [SaleDate] a valid Date Datatype? Or is it a Text Datatype field?
And I still don't know if the [SaleDate] field includes a time value
or not.
Try this:
Change the query criteria for the [SaleDate] field to:

Between DateAdd("d",-90,[Enter a Date]) and DateAdd("d",- 89,
[Enter a Date])

You will be prompted just once to enter one date.
Enter the date in US date format
Month/day/year.
Do you get a record exactly 90 days old from that date (assuming there
is at least one)?
If you still have difficulty, post the entire query SQL.
--
Fred
Please only reply to this newsgroup.
I do not reply to personal email.
.
 
Thank you. You are right, the criteria wasn't in the
right place, as another respondent pointed out. This is
the code and problem I have now (which I also posted in
the other thread under my problem. - Please educate me if
this sort of double-post is not proper etiquette for these
fantastic newsgroups.) Also, it seems that I should take
another class - any suggestions? Access
Intermediate/Advanced or VB or SQL?? I looked at CompUsa
online classes to try that, but I thought I'd ask here.

Here it is now, along with the next problem.

I got the date thing to work. Now, I put in "Count(*) >1"
under the Cashier column. And I only get one date
(1/27/04) and only one record per cashier, when each of
the 3 displayed have at least 2 days with the problem I'm
looking to display. And I'm not getting the other
cashiers who have more than 1 day of having +/- $5 in the
time period.

Here is the code:

SELECT [T: Cashier OverShort].SALEDATE, [Static Store
Info].StoreName, [T: Cashier OverShort].Cashier, [T:
Cashier OverShort].LastName, [T: Cashier
OverShort].FirstName, [T: Cashier OverShort].OverShort
FROM [T: Cashier OverShort] INNER JOIN [Static Store Info]
ON [T: Cashier OverShort].STNum = [Static Store Info].StNum
GROUP BY [T: Cashier OverShort].SALEDATE, [Static Store
Info].StoreName, [T: Cashier OverShort].Cashier, [T:
Cashier OverShort].LastName, [T: Cashier
OverShort].FirstName, [T: Cashier OverShort].OverShort,
[T: Cashier OverShort].Cashier, [T: Cashier
OverShort].STNum, [T: Cashier OverShort].OverShort
HAVING ((([T: Cashier OverShort].SALEDATE) Between DateAdd
("d",-30,[EnterDate]) And [EnterDate]) AND (([T: Cashier
OverShort].OverShort)>4.99 Or ([T: Cashier
OverShort].OverShort)<-4.99) AND (Count(*)>1))
ORDER BY [T: Cashier OverShort].SALEDATE, [T: Cashier
OverShort].LastName, [T: Cashier OverShort].STNum;


Sample Data: (Just Date, Store, Cashier, OverShort)
1/15 Lynn 5703 (10.00)
1/20 Lynn 5703 10.63
1/17 Swansea 11207 (6.11)
1/4 Swansea 11207 (9.93)
1/27 Worcester 12513 (10.00)
1/27 Lynn 15318 (9.90)
1/27 Norwood 16228 (64.46)
1/30 Worcester 12513 (10.29)
1/3 Cranston 2334 (27.92)
1/3 Cranston 2482 18.44
1/3 Somerville 2287 9.91

With the code above, I only get the 3 1/27 records, and
not the 1/15 and 1/20 for 5703, or 1/17 and 1/4 for 11207.

ALSO, 15318 and 16228 have only 1 error in the time
period, so I don't know why they were selected.

I am stumped, and, again, ask for (and so greatly
appreciate) your help.
sara
-----Original Message-----
Sara, if SaleDate is a Date/Time field in a query, then there has to be
something else going on.

Are you using criteria under the calculated field?

Is the query doing any aggegation (e.g. GROUP BY)?

Switch the query to SQL View (View menu), and post the entire SQL statement
here.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Thank you. I tried your code (and the other suggestions)
and I still get the Type Mismatch error. SaleDate is the
field from my table, and it is a date. I have also
formatted it in the query as shortdate, and in the table
the data is mm/dd/2004.

Any further thoughts?
Thanks.
Sara

-----Original Message-----
What is SaleDate? Looks like Accesss does not recognise it as a date.

If it is a Text type field in a table, or a calculated date in a query, try:
DateAdd("d",-90,CVDate([SaleDate]))

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

I am getting "Type Mismatch in Expression" in my query.
What am I doing wrong here? I need to find a data 90 days
earlier than a date a user enters as a parameter.

DateAdd("d",-90,[SaleDate])

Also tried DateAdd("m",-3,[SalesDate])

Is this allowed in Access? How can I get my date?
Thanks


.


.
 
Back
Top