473,396 Members | 1,995 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Data Type Mismatch In Query

I have 2 queries which have been working for the last 2 or 3 years but last week decided to start giving me a data type mismatch error. Query 1 looks at how many records have been created in the last 31 days so that I can count visits, and query 2 looks at how many visits I have each day (Today)
I rewrote the queries and they worked for a few hours and then fell over again. I have tried to compact and repair but that hasn't changed anything. I made a different query and added a new field to the table that displayed the date without the time and based the query on that field instead of the query field [Date31] and that worked up until today but now if I run the query it returns all the records but then gives the data type mismatch error and on clicking ok, all fields change to “#Name?” If I take out the Criteria ie ask for all records, all 29k records are returned as expected. As soon as I filter it all goes south.
I really don’t know where to go from here? Is my database corrupted and if so do I need to rebuild the entire back end and import the data? Any advice would be greatly appreciated, my ability level in access terms is mediocre at best

SQL for Query 1 “AttMonth” is as follows.

Expand|Select|Wrap|Line Numbers
  1. SELECT Attendance.Att_ID
  2.    , Attendance.Att_ClientNo
  3.    , Attendance.Att_Date
  4.    , DateValue([Att_date]) AS Date31
  5. FROM Attendance
  6. WHERE (((DateValue([Att_date]))>Date()-31))
  7. ORDER BY DateValue([Att_date]);
Thank you.
Feb 24 '14 #1

✓ answered by zmbd

Double check your SQL - typically there's an extra/missing something (^_^) I've tested the following within my test database by copying and modifying one of the data tables to match the fields you gave - it returned 120 records:

Expand|Select|Wrap|Line Numbers
  1. SELECT Attendance.Att_ID 
  2.    , Attendance.Att_ClientNo 
  3.    , Attendance.Att_Date 
  4.    , DateValue([Att_date]) AS Date31 
  5. FROM Attendance 
  6. WHERE ( [Att_Date] > Dateadd("d",-31,Date()))
  7. ORDER BY [Att_date]; 

6 4632
zmbd
5,501 Expert Mod 4TB
Have you recently upgraded your versions of Office/Access?

Are people with different versions of Office/Access opening your database?

You mention frontend/backend in your post, are your queries in the backend?

You might want to
"[Att_Date]" is this a text field in the table?

If [Att_Date] is a date field then you should be able to remove the datevalue() function and change the "Date() - 31" to Dateadd("d",-31,Date()) so that you are dealing with all date/time datatype.
Feb 24 '14 #2
Thanks for your reply.
"[Att_Date]" is a date/time field in the table
All the queries are in the front end, only tables sit on my back end.
Removing the datevalue() function and using Dateadd in the criteria stops the error but returns 0 records, have I misunderstood?
Thanks for your help.
Feb 24 '14 #3
mcupito
294 256MB
" I made a different query and added a new field to the table that displayed the date without the time and based the query on that field instead of the query field [Date31]"

How did you do this? It really sounds like there is a miscommunication between the DateTime / Date fields. I would check the property sheets for the appropriate fields you think are giving the error and double check that Time isn't being pulled in from somewhere.

You can always try to use formatting to get a desired results.
Expand|Select|Wrap|Line Numbers
  1. Format([Att_Date], "Short Date") 
or something similar
Feb 24 '14 #4
zmbd
5,501 Expert Mod 4TB
Double check your SQL - typically there's an extra/missing something (^_^) I've tested the following within my test database by copying and modifying one of the data tables to match the fields you gave - it returned 120 records:

Expand|Select|Wrap|Line Numbers
  1. SELECT Attendance.Att_ID 
  2.    , Attendance.Att_ClientNo 
  3.    , Attendance.Att_Date 
  4.    , DateValue([Att_date]) AS Date31 
  5. FROM Attendance 
  6. WHERE ( [Att_Date] > Dateadd("d",-31,Date()))
  7. ORDER BY [Att_date]; 
Feb 24 '14 #5
Double checked my SQL and there was indeed an error. I am still at a loss as to why a query that was happy for 2 or 3 years would decide to stop behaving but using dateadd is doing the job nicely so I wont worry :)

Thank you so much for your help it is much appreciated.
Feb 24 '14 #6
zmbd
5,501 Expert Mod 4TB
I usually blame Updates and MS Gremlins?!
However, Ghost in the Shell?
Feb 24 '14 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Laurel | last post by:
this is driving me crazy. i need to use a form control as a criteria in a select query, and the control's value is set depending upon what a user selects in an option group on the form. the query...
0
by: s_gregory | last post by:
The mdb is considerable size 70 +- mb. A complex union query was working well, but when an additional union select... was added into the query, selecting identical fields from a different source,...
0
by: news.paradise.net.nz | last post by:
I have been developing access databases for over 5 years. I have a large database and I have struck this problem with it before but can find nothing in help or online. Access 2000 I have a query...
1
by: ArcadeJr | last post by:
Good morning all! I have been getting a Run-time Error message #3464 - Data Type mismatch in criteria expression. While trying to run a query. I have a database where the field Asset_Number...
3
by: martlaco1 | last post by:
Trying to fix a query that (I thought) had worked once upon a time, and I keep getting a Data Type Mismatch error whenever I enter any criteria for an expression using a Mid function. Without the...
2
by: igor.barbaric | last post by:
Hello! I have created a very simple query like this: SELECT Tasks.Name, DurationHrs(,) AS Duration FROM Tasks INNER JOIN Log ON Tasks.TaskID=Log.TaskID; The above query works fine....
1
by: Igor Barbaric | last post by:
Hello! I have created a very simple query like this: SELECT Tasks.Name, DurationHrs(,) AS Duration FROM Tasks INNER JOIN Log ON Tasks.TaskID=Log.TaskID; The above query works fine....
4
by: bleighfield | last post by:
Hi everyone Hope someone can help with this one.. Background: I work in vehicle fleet, I have built something to 'predict' when a car/van service is due (it's fairly simple, calculates...
2
by: psychomad | last post by:
Please, can someone help me out to solve this error, i've been searching throughout my codes and yet i didnt succeed in finding the error!!!! The Error is: Server Error in '/' Application....
19
by: Lysander | last post by:
I have written a query that takes three integers representing day,month and year, forms a date from them and compares this date to the date the record was entered and returns any records where the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.