473,387 Members | 1,536 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,387 software developers and data experts.

Data Type Mismatch in criteria Expression (modded fuzzy string match)

Taken (and modded) from http://www.codeguru.com/vb/gen/vb_misc/tips/
article.php/c13137

'RESULTS' table:

REF_STRING - TEXT 250
TEST_STRING - TEXT 250
MATCH_VALU - SINGLE FIXED 2 DECIMAL PLACES

(I also have three additional fields but they are not used in this
query - id, fid, good_match)
>From the query:
INSERT INTO RESULTS ( REF_STRING, TEST_STRING, MATCH_VALU )
SELECT REF_LIST.REF_STRING, TEST_LIST.TEST_STRING, LCS([REF_STRING],
[TEST_STRING]) AS Expr1
FROM REF_LIST, TEST_LIST
WHERE (((LCS([REF_STRING],[TEST_STRING]))>0.79));

---

Public Function LCS(String1 As String, String2 As String, Optional
AlgInUse) As Single
'* *************** Longest Common Subsequence *********************
'* The LCS is calculated by the length of the longest common,
'* not necessarily contiguous, sub-sequence of characters divided by
'* the average character lengths of both strings.
'* In this case: c(m, n) / (((Str1Len) + (Str2Len)) / 2))
'* LCS is symmetric.
'*
'* str1 and str2 are arrays.
'************************************************* ***********************

Dim STR1() As Byte
Dim STR2() As Byte

STR1 = StrConv(String1, vbFromUnicode)
STR2 = StrConv(String2, vbFromUnicode)

Dim i As Integer, j As Integer, m As Integer, n As Integer
Dim c() As Integer, b() As Integer, X$(), Y$()
Dim Str1Len As Integer, Str2Len As Integer, SmStr(), LgStr()

If IsMissing(AlgInUse) Then AlgInUse = ""

Str1Len = UBound(STR1)
Str2Len = UBound(STR2)

n = Minimum(Str1Len, Str2Len)
m = Maximum(Str1Len, Str2Len)

ReDim X(m)
ReDim Y(m)
ReDim c(m, m)
ReDim b(m, m)

If Str1Len Str2Len Then
For i = 0 To Str1Len - 1
X(i) = STR1(i)
Next i
For i = 0 To Str2Len - 1
Y(i) = STR2(i)
Next i
Else
For i = 0 To Str2Len - 1
X(i) = STR2(i)
Next i
For i = 0 To Str1Len - 1
Y(i) = STR1(i)
Next i
End If ' Str1Len Str2Len

For i = 1 To m
For j = 1 To n
If X(i - 1) = Y(j - 1) Then
c(i, j) = c(i - 1, j - 1) + 1
b(i, j) = 1 ' /* from north west */
ElseIf c(i - 1, j) >= c(i, j - 1) Then
c(i, j) = c(i - 1, j)
b(i, j) = 2 ' /* from north */
Else
c(i, j) = c(i, j - 1)
b(i, j) = 3 ' /* from west */
End If
Next j
Next i

' return c[m][n];

If c(m, n) 0 Then
If AlgInUse = "Dmph" Or AlgInUse = "SSLCS" Then
LCS = c(m, n) ' Longest Common Subsequence
Else
LCS = CSng(Format((c(m, n) / (((Str1Len) + (Str2Len)) / 2)),
"#.##"))
End If
Else
LCS = 0
End If

Erase X
Erase Y
Erase c
Erase b

End Function

Feb 12 '07 #1
6 4604
>INSERT INTO RESULTS ( REF_STRING, TEST_STRING, MATCH_VALU )
>SELECT REF_LIST.REF_STRING, TEST_LIST.TEST_STRING, LCS([REF_STRING],
[TEST_STRING]) AS Expr1
FROM REF_LIST, TEST_LIST
WHERE (((LCS([REF_STRING],[TEST_STRING]))>0.79));

I'm not familiar with the function you are trying to use, but aren't
you calling the LCS function twice in this query?
You call it once in the field list and alias the field as Expr1, then
again in the WHERE clause.
I would think that your WHERE statement could simply be
WHERE([Expr1]>0.79);

Feb 13 '07 #2
On Feb 12, 9:27 pm, "storrboy" <storr...@sympatico.cawrote:
I would think that your WHERE statement could simply be
WHERE([Expr1]>0.79);
Yeah, I tried that before and just again when you suggested it. It
creates a pop up box that asks me for Expr1 as a parameter value.

I might need to contact the author. I thought it might be obvious to
someone else though.

Thanks,

Christian

Feb 13 '07 #3
On Feb 13, 11:24 am, christianlo...@yahoo.com wrote:
On Feb 12, 9:27 pm, "storrboy" <storr...@sympatico.cawrote:
I would think that your WHERE statement could simply be
WHERE([Expr1]>0.79);

Yeah, I tried that before and just again when you suggested it. It
creates a pop up box that asks me for Expr1 as a parameter value.

I might need to contact the author. I thought it might be obvious to
someone else though.

Thanks,

Christian

No, you actually need both (you can't reference Expr1 in your where
clause).

I'm not sure what the actual question is here (maybe my newsreader
truncated it), but perhaps you are missing a join between REF_LIST and
TEST_LIST, e.g.

INSERT INTO RESULTS ( REF_STRING, TEST_STRING, MATCH_VALU )
SELECT REF_LIST.REF_STRING, TEST_LIST.TEST_STRING, LCS([REF_STRING],
[TEST_STRING]) AS Expr1
FROM REF_LIST
INNER JOIN TEST_LIST
ON REFLIST.ID = TEST_LIST.ID
WHERE (((LCS([REF_STRING],[TEST_STRING]))>0.79));

Also if REF_STRING or TEST_STRING exist in both tables you'll need to
make that clear where you reference the fields in your SELECT, e.g.

LCS([REF_STRING],[TEST_STRING]) maybe should be
LCS(REF_LIST.REF_STRING, TEST_LIST.TEST_STRING)

(you don't need the brackets)

Bruce

Feb 13 '07 #4
On Feb 13, 12:30 pm, "Bruce" <deluxeinformat...@gmail.comwrote:
No, you actually need both (you can't reference Expr1 in your where
clause).

I'm not sure what the actual question is here (maybe my newsreader
truncated it), but perhaps you are missing a join between REF_LIST and
TEST_LIST, e.g.

INSERT INTO RESULTS ( REF_STRING, TEST_STRING, MATCH_VALU )
SELECT REF_LIST.REF_STRING, TEST_LIST.TEST_STRING, LCS([REF_STRING],
[TEST_STRING]) AS Expr1
FROM REF_LIST
INNER JOIN TEST_LIST
ON REFLIST.ID = TEST_LIST.ID
WHERE (((LCS([REF_STRING],[TEST_STRING]))>0.79));

Also if REF_STRING or TEST_STRING exist in both tables you'll need to
make that clear where you reference the fields in your SELECT, e.g.

LCS([REF_STRING],[TEST_STRING]) maybe should be
LCS(REF_LIST.REF_STRING, TEST_LIST.TEST_STRING)

(you don't need the brackets)
Thanks for taking the time to look at this.

There is no join between the tables. Also, in Ref_List there is only
one field, Ref_String, in Test_List there is only one field,
Test_String.

The problem is it starts the query for a bit then pops up with the
error message " Data Type Mismatch in Criteria Expression "

I assume it's because of the Single datatype, but the table has the
correct data type (RESULTS - MATCH_VALU) and the function formats the
result as a single.

The error message is obviously referring to

WHERE (((LCS([REF_STRING],[TEST_STRING]))>0.79));

but I can't tell what's wrong with it.
Christian
Feb 13 '07 #5
On Feb 13, 2:23 pm, christianlo...@yahoo.com wrote:
On Feb 13, 12:30 pm, "Bruce" <deluxeinformat...@gmail.comwrote:
No, you actually need both (you can't reference Expr1 in your where
clause).
I'm not sure what the actual question is here (maybe my newsreader
truncated it), but perhaps you are missing a join between REF_LIST and
TEST_LIST, e.g.
INSERT INTO RESULTS ( REF_STRING, TEST_STRING, MATCH_VALU )
SELECT REF_LIST.REF_STRING, TEST_LIST.TEST_STRING, LCS([REF_STRING],
[TEST_STRING]) AS Expr1
FROM REF_LIST
INNER JOIN TEST_LIST
ON REFLIST.ID = TEST_LIST.ID
WHERE (((LCS([REF_STRING],[TEST_STRING]))>0.79));
Also if REF_STRING or TEST_STRING exist in both tables you'll need to
make that clear where you reference the fields in your SELECT, e.g.
LCS([REF_STRING],[TEST_STRING]) maybe should be
LCS(REF_LIST.REF_STRING, TEST_LIST.TEST_STRING)
(you don't need the brackets)

Thanks for taking the time to look at this.

There is no join between the tables. Also, in Ref_List there is only
one field, Ref_String, in Test_List there is only one field,
Test_String.

The problem is it starts the query for a bit then pops up with the
error message " Data Type Mismatch in Criteria Expression "

I assume it's because of the Single datatype, but the table has the
correct data type (RESULTS - MATCH_VALU) and the function formats the
result as a single.

The error message is obviously referring to

WHERE (((LCS([REF_STRING],[TEST_STRING]))>0.79));

but I can't tell what's wrong with it.

Christian

Can REF_STRING or TEST_STRING ever be null? If so, I bet that's what
the problem is. Your LCS function will crash if either of these are
null.

Bruce

Feb 14 '07 #6
On Feb 14, 12:14 pm, "Bruce" <deluxeinformat...@gmail.comwrote:
Can REF_STRING or TEST_STRING ever be null? If so, I bet that's what
the problem is. Your LCS function will crash if either of these are
null.
ARG! That was it mate!

THANKS!!

Feb 14 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

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...
1
by: amitbadgi | last post by:
I am getting the following error while converting an asp application to asp.net Exception Details: System.Runtime.InteropServices.COMException: Data type mismatch in criteria expression. ...
10
by: aaronrm | last post by:
I have a real simple cross-tab query that I am trying to sum on as the action but I am getting the "data type mismatch criteria expression" error. About three queries up the food chain from this...
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...
1
by: Bobby Edward | last post by:
Using Access db with VS2008 (ASP.NET/VB.NET).... On the INSERT command I get this error: System.Data.OleDb.OleDbException: Data type mismatch in criteria expression. I haven't found a...
6
by: samuel84 | last post by:
Hi, I am getting the error "invalid use of null" when summing value from a range which has no value and "data type mismatch in criteria expression" when there are values to be summed up. Is there...
9
by: nixonmg | last post by:
When the Command Button "Notify" is clicked, I am wanting to send out an email to the user with appropriate information in the email (works great), check the "Notified" check box (does not work), and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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,...
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,...

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.