473,769 Members | 5,823 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Datatype mismatch when ordering or searching field criteria

11 New Member
I am working in Access 2007 attempting to grab 2 characters from a text field named ProjectNumber. After determining what 2 digits to add in front to make it a year, I need to do that. I have done that in the code below to create a value for "intPN". I then need that value to become a number so that I can compare it to a range of years (1983-1987). The code below returns the 4 character year as intended. But I get a Datatype mismatch error whenever I try to order or use a critera (where) based on that field. I have been playing with this code for 2 days and am ready to go postal if the Datatype mismatch error pops up too many more times. So any help would really be appreciated. It is probably something really simple and I am too thick to see it. Thanks.

Expand|Select|Wrap|Line Numbers
  1. SELECT ArcFilz.ProjectNumber, IIf(Len([ProjectNumber])>=7 And [ProjectNumber] Not Like "*P*" And [ProjectNumber] Not Like "*S*",IIf(CInt(Mid([ProjectNumber],3,2))>80,CInt("19"+Mid([ProjectNumber],3,2)),CInt("20"+Mid([ProjectNumber],3,2))),1960) AS intPN
  2. FROM ArcFilz;
Oct 9 '09 #1
9 2225
CroCrew
564 Recognized Expert Contributor
Hello rscheinberg,

Are you trying to do all this within Microsoft Access? Or is the database just in Microsoft Access and the front end is in Classic ASP?

CroCrew~
Oct 9 '09 #2
rscheinberg
11 New Member
The database is actually in Access and the front end will be in ASP. I couldn't get the code to work in ASP so I went directly to the database and am building a query there to get it right before I go back to the ASP page. I have a suspicion that it has something to do with the attempt to convert the text strings to integers, but I am at a loss.

Thanks.
Oct 9 '09 #3
CroCrew
564 Recognized Expert Contributor
Hello rscheinberg,

Can you tell us the tables that you’re using and the fields within the tables too? Also, if you could provide two rows of data from the tables so we can understand what is in them.

I believe that we can help you,
CroCrew~
Oct 9 '09 #4
rscheinberg
11 New Member
The only table I am accessing is called ArcFilz. And the only field I am calling is ProjectNumber, which is a text field. However here are 2 lines of data from the entire table. Thank you again for looking at this.

Expand|Select|Wrap|Line Numbers
  1. ID    ArchiveType    Container    ProjectNumber    ProjectName    Office    Location    ShelfNumber    FileType    Files    Department    ProjectManager    CheckedOut    CheckedOutDate    ReturnDate    Missing    Destroyed    Deleted    DeleteNote    Deleter    Archived    ArchivedBy    Entered    EnteredBy    ReviewDate
  2. 12172    Dead Files    Z-9999    010213300    Schilling Farms Lot 1 Site Plan-Greene    Memphis, TN    Toyota Plaza (5)        Binders, Guidelines, Maps    Test    Residential    05877                    09/23/04    9/23/2004    This was a test item.    lrk-net\tuckerd                    
  3. 13252    Dead Files    T2107    01P194600        Memphis, TN    Toyota Plaza (B)        Project Files    forms submitted by Rose Pollion                                            8/17/2005    05543    8/17/2005    05674    
Oct 9 '09 #5
CroCrew
564 Recognized Expert Contributor
So the first two numbers from the field "ProjectNum ber" is the end part of a year? Both the records above are for the year 2001?
Oct 9 '09 #6
rscheinberg
11 New Member
That is correct. The 3rd and 4th characters in the project number represent the last 2 digits of the year. Actually, the second row of data (with the "P" in it) does not follow that rule, so I am making those display as 1960 (before any of our projects began) to get them out of the mix. I am doing this with the IIF() statement. But you are getting the idea of what I am trying to do. Once I have the 2 characters from the project number, I am sticking either 19 or 20 in front of them depending on the year (using another IIF() statement) and then converting that string to a number using CInt(). That should give me a year in the yyyy format as intPN. The query does all that correctly. What I would do next is query for all records where intPN was between two numbers, say 1982 and 1988.

But even when I try to simply order by or filter the data in that field (intPN) in any way I get the Datatype mismatch error. I don't get an error if I am ordering or filtering by the ProjectNumber field itself.

It's curious.

Thanks again.
Oct 9 '09 #7
CroCrew
564 Recognized Expert Contributor
So is it the 1st and 2nd characters that are the last 2 digits of a year or the 3rd and 4th characters?
Oct 9 '09 #8
rscheinberg
11 New Member
The 3rd and 4th characters. But I am testing for only those project numbers that have 7 or more characters and do not have letters in them. Those projects do not follow the pattern. In some records the project number is even blank. Here is some sample data that will show you what I have:
Expand|Select|Wrap|Line Numbers
  1. ID             PROJECTNUMBER            PROJECTNAME
  2. 1              0S9011000                 Project 1
  3. 2              009014100                 Project 2
  4. 3              009629000                 Project 3
  5. 4                                        Project 4
  6. 5              010016200                 Project 5
  7. 6              009103900                 Project 6
  8. 7              008500700                 Project 7
  9. 8              008806600                 Project 8
  10. 9              008911200                 Project 9
  11. 10             009203800                 Project 10
  12. 11             030103112                 Project 11
  13. 12             010203400                 Project 12
  14. 13             020005902                 Project 13
  15. 14             009709700                 Project 14
  16. 15             P148500                   Project 15
  17.  
Oct 9 '09 #9
CroCrew
564 Recognized Expert Contributor
Hello rscheinberg,

Sorry for not getting back to you earlier with something but, I don’t really understand why you’re doing all this. To me it seems that you should have a field within your database that has the value of “ProjectBeganDa te” if you’re going to hit the database many times querying for a project began date within a text field.

With that said maybe this can help you with the solution you’re looking for.

Expand|Select|Wrap|Line Numbers
  1. <%  
  2.     Set adoCon = Server.CreateObject("ADODB.Connection")  
  3.     adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("Relative path to your Access database")   
  4.     Set rsData = Server.CreateObject("ADODB.Recordset")  
  5.  
  6.     SQL = "SELECT ID, ProjectNumber, ProjectName FROM ArcFilz"
  7.     rsData.CursorType = 2  
  8.     rsData.LockType = 3  
  9.     rsData.Open SQL, adoCon  
  10.  
  11.     Do Until (rsData.EOF) 
  12.         If (IsNumeric(rsData("ProjectNumber").value)) Then
  13.             If (Right(DatePart("yyyy",Date), 2) > Right(Left(rsData("ProjectNumber").value, 4), 2)) Then
  14.                 ProjectBeganDate = Left(DatePart("yyyy",Date), 2) & Right(Left(rsData("ProjectNumber").value, 4), 2)
  15.             Else
  16.                 ProjectBeganDate = (Left(DatePart("yyyy",Date), 2) - 1) & Right(Left(rsData("ProjectNumber").value, 4), 2)
  17.             End If
  18.         Else
  19.             ProjectBeganDate = "1960"
  20.         End If
  21.  
  22.         Response.Write("Is " & rsData("ProjectName").value & " (ProjectNumber = " & rsData("ProjectNumber").value & ") between the range of years (1983-1987)? <b>" & ProjectBeganDate & " - ")
  23.         If ((ProjectBeganDate >= 1983) AND (ProjectBeganDate <= 1987)) Then
  24.             Response.Write("Yes")
  25.         Else
  26.             Response.Write("No")
  27.         End If
  28.         Response.Write("</b> <br />")
  29.  
  30.         rsData.MoveNext 
  31.     Loop 
  32. %>  
  33.  
Hope this helps,
CroCrew~
Oct 12 '09 #10

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

Similar topics

2
2927
by: Stephen Briley | last post by:
For some reason, my posts are scrubbed as attachments. Lets hope that sending from the yahoo account works. I'm new to Python and I'm trying to do some database work with MS Access, but I can't seem to get around a "datatype mismatch error". Here's an example table that I'm working with... ID name dept 1 steve acct
2
2124
by: Steve Briley | last post by:
I'm new to Python and I'm trying to do some database work with MS Access, but I can't seem to get around a "datatype mismatch error".&nbsp; Here's an example table that I'm working with... &nbsp; ID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name&nbsp;&nbsp;&nbsp; dept 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; steve&nbsp;&nbsp; acct
3
3977
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 results should return information on either a single employee or all employees. the problem that i have is that if i type in "*" (but without quotes) in the QBE criteria, it works fine. however, if i use Iif() to determine whether or not there...
1
2487
by: Ken | last post by:
I wrote a function to use in queries that takes a date and adds or subtracts a certain length time and then returns the new value. There are times when my function needs to return Null values. Function DateCalc (blah...) As Variant Do Stuff... If Not IsNull(varNewDate) Then DateCalc = varNewDate End If End Function
33
2515
by: Geoff Jones | last post by:
Hiya I have a DataTable containing thousands of records. Each record has a primary key field called "ID" and another field called "PRODUCT" I want to retrieve the rows that satisy the following criteria: I have a list of about 100 numbers which correspond to the ID field and also another 40 say numbers corresponding to the numbers in the PRODUCT field. I want to show the rows that correspond to both these criteria.
6
3395
by: rn5a | last post by:
I am inserting records in a MS-Access database table. The data type of one of the columns named *OrderDate* in the DB table is Date/Time. This is the SQL query I am using to insert the records in the Access DB table: =============================== strSQL = "INSERT INTO Cart (CartID, ProductID, Quantity, Total, OrderDate) VALUES (CID, PID, Qty, TotalAmt, ODate)" oleDbCmd = New OleDbCommand(strSQL, oleDbConn)
2
1559
by: chirag1989 | last post by:
I m havin an error of datatype mismatch actual here i m askin user to input the code in text box and then searchin the record havin that code in database the problem is the code field Bnum is of number datatype so its showin me this error Microsoft JET Database Engine (0x80040E07) Data type mismatch in criteria expression. /library/12updbook1.asp, line 128
0
1233
by: Snoopy33 | last post by:
I have a query that builds a date from a text field with the date imput as yyyymmdd in the query, so i have to piece it together in my expression as follows: exp: FormatNumber(DateDiff("d",DateSerial(Left(, 4),Left(Right(,4),2),Right(,2)),Now()))) if i don't use a criteria, it works fine. when i try to use the criteria <7 is when i get the error. It will show the correct records
14
1890
by: rscheinberg | last post by:
I am working in Access 2007 attempting to grab 2 characters from a text field named ProjectNumber. After determining what 2 digits to add in front to make it a year, I need to do that. I have done that in the code below to create a value for "intPN". I then need that value to become a number so that I can compare it to a range of years (1983-1987). The code below returns the 4 character year as intended. But I get a Datatype mismatch in criteria...
0
9586
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10210
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10043
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9861
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8869
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7406
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5298
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3956
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.