Solved

Data Type Mismatch in Criteria Expression in MS Access

Posted on 2011-03-11
14
435 Views
Last Modified: 2012-06-27
I have a linked tab delimited text file that will be updated monthly from a source outside my group, with the new file written to the LAN.  I have an Access 2007 database I am using to link back to that file, which is then the source of several queries.  One field, [Job Code], has both alpha and numeric values (A247, 709, L432, SS954) of varying lengths.

I have a query I run that needs to look at only job codes less than 1000.   I found a function below on line as a way to strip these values down to only their numeric component (please see attached code), and then tried to use <1000 as the critiera.  The query will run and return values, but within about 5 to 10 seconds, the "Data Type Mismatch..." error appears and all of the values change to a #NAME? value within the result set.

**Some things of note that may help are:  1) I only need the values that contain numeric values only.  If the string has an alpha character, it can be excluded 2) I've tried the Val(...) and CInt(...) functions and got the same issue 3) There are no blank values in the Job Code field 4) Character values will only be in the first two characters of the Job Code field ***

I'm hoping for a workaround or some guidance on what the underlying issue is so that I can simply filter these records in the actual query, which will be used to write data to other databases for various departments within our organization that aren't allowed to see data from other departments.
Public Function NumericValue( strFullValue As String) as String
 Dim lngLoop As Long
 Dim strReturn As String

 For lngLoop = 1 To Len(strFullValue)
 If IsNumeric(Mid(strFullValue,lngLoop,1)) Then
 strReturn = strReturn & Mid(strFullValue,lngLoop,1)
 End If
 Next lngLoop

 NumericValue = strReturn

 End Function

**********************

I then call it in the query as

JCode: NumericValue([Job Code])

Open in new window

0
Comment
Question by:UTSWPeds
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +2
14 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 35109973
try using < "1000" as the criteria
0
 

Author Comment

by:UTSWPeds
ID: 35110023
Same issue...plus during the 5-10 seconds when I did get a result set, it showed records that were greater than 1000.
0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 34 total points
ID: 35110159
try changing the function to return  Long instead of string

Public Function NumericValue( strFullValue As String) as Long
 Dim lngLoop As Long
 Dim strReturn As Long

 For lngLoop = 1 To Len(strFullValue)
 If IsNumeric(Mid(strFullValue,lngLoop,1)) Then
 strReturn = strReturn & Mid(strFullValue,lngLoop,1)
 End If
 Next lngLoop

 NumericValue = strReturn

 End Function

Open in new window



then, use this criteria

  < 1000


0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 6

Expert Comment

by:Patrick Tallarico
ID: 35110177
In the query where you are using this code, are there any other tables joined to the text file table?  
0
 

Author Comment

by:UTSWPeds
ID: 35110279
Still the same issue, unfortunately.

My thoughts wander to whether or not this is an issue with the link back to the text file.  I've updated the link and opened the file in wordpad and it appeared fine, however.
0
 
LVL 53

Expert Comment

by:Huseyin KAHRAMAN
ID: 35110291
what is the query that you run
0
 

Author Comment

by:UTSWPeds
ID: 35110294
No other tables joined to this file.

0
 

Author Comment

by:UTSWPeds
ID: 35110317
The query is basically a select * from the file.  At this stage, I'm just trying to create smaller datasets for distribution to departments from the master file.  

The only field I do anything at all with is the Job Code, which I run the function against to capture the numeric values.
0
 
LVL 53

Expert Comment

by:Huseyin KAHRAMAN
ID: 35110383
can you please post a sample db containing the table with sample data, function that you use plus a sample query to show the issue...
0
 
LVL 6

Assisted Solution

by:Patrick Tallarico
Patrick Tallarico earned 34 total points
ID: 35110409
one way to test to see if it is the function, or the file is to temporarily import the text file into access as a regular local table, then run the same query with the same function on that to see if you get the same error.
0
 
LVL 53

Assisted Solution

by:Huseyin KAHRAMAN
Huseyin KAHRAMAN earned 34 total points
ID: 35110474
check this, it is working fine
SELECT Numericvalue(JobCode) AS JobNo, JobCode, Jobname
FROM Jobs
WHERE Numericvalue(JobCode)<500;


with this function in Module 1

Public Function NumericValue(strFullValue As String) As String
    Dim lngLoop As Long
    Dim strReturn As String

    For lngLoop = 1 To Len(strFullValue)
        If IsNumeric(Mid(strFullValue, lngLoop, 1)) Then
            strReturn = strReturn & Mid(strFullValue, lngLoop, 1)
        End If
    Next lngLoop

    NumericValue = strReturn
End Function

Open in new window

JobCodes.mdb
0
 
LVL 50

Accepted Solution

by:
Gustav Brock earned 398 total points
ID: 35110532
Try with:

JCode: NumericValue(Nz([Job Code]))

/gustav
0
 

Author Closing Comment

by:UTSWPeds
ID: 35110643
The NZ function worked perfectly, but I gave points to other contributors as well for effort and that given the information they had at hand, their solutions were likely workable as well.
0
 
LVL 50

Expert Comment

by:Gustav Brock
ID: 35110695
You are welcome!

/gustav
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question