PC Review


Reply
Thread Tools Rate Thread

Datatype mismatch in criteria expression

 
 
blobb
Guest
Posts: n/a
 
      14th Jul 2009
I am trying to build a recordset off of an entry on a form that "sounds like"
or is similiar to the current entry. I have the below code that was working
well last time I used it but I am now getting the "Data type mismatch error
in criteria expression". Could someone help me identify why this is? I have
tried double quotes, single quotes, no quotes...

The "Soundex" is the function for the sounds like, [Crosswalk] is existing
table.


Dim rst As dao.Recordset
Dim strLast As String
Dim db As Database

Set db = CurrentDb()

'If on a new row.
If (Me.NewRecord = True) Then
'...check for duplicate Lastnames.
If Not IsNothing(Me.LastName) Then
' Open a recordset to look for duplicate Lastnames.
Set rst = CurrentDb.OpenRecordset("SELECT PTid, Lastname,
FirstName, SSN FROM " & _
"Crosswalk WHERE Soundex([Lastname]) = '" &
Soundex(Me.LastName) & "'")

Thanks! blobb
 
Reply With Quote
 
 
 
 
John Spencer
Guest
Posts: n/a
 
      14th Jul 2009
It could be your soundex function is having a problem. Are there any records
in Crosswalk where LastName is null or a zero-length string? If so, do the
Soundex function handle those cases?

You might try testing with
IIF(Len(LastName & "") = 0,"zxvq",LastName)
to force a "legal" value to be passed to the Soundex function.

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

blobb wrote:
> I am trying to build a recordset off of an entry on a form that "sounds like"
> or is similiar to the current entry. I have the below code that was working
> well last time I used it but I am now getting the "Data type mismatch error
> in criteria expression". Could someone help me identify why this is? I have
> tried double quotes, single quotes, no quotes...
>
> The "Soundex" is the function for the sounds like, [Crosswalk] is existing
> table.
>
>
> Dim rst As dao.Recordset
> Dim strLast As String
> Dim db As Database
>
> Set db = CurrentDb()
>
> 'If on a new row.
> If (Me.NewRecord = True) Then
> '...check for duplicate Lastnames.
> If Not IsNothing(Me.LastName) Then
> ' Open a recordset to look for duplicate Lastnames.
> Set rst = CurrentDb.OpenRecordset("SELECT PTid, Lastname,
> FirstName, SSN FROM " & _
> "Crosswalk WHERE Soundex([Lastname]) = '" &
> Soundex(Me.LastName) & "'")
>
> Thanks! blobb

 
Reply With Quote
 
blobb
Guest
Posts: n/a
 
      14th Jul 2009
The last name is a required field -- there are no blanks. Any other ideas?

"John Spencer" wrote:

> It could be your soundex function is having a problem. Are there any records
> in Crosswalk where LastName is null or a zero-length string? If so, do the
> Soundex function handle those cases?
>
> You might try testing with
> IIF(Len(LastName & "") = 0,"zxvq",LastName)
> to force a "legal" value to be passed to the Soundex function.
>
> John Spencer
> Access MVP 2002-2005, 2007-2009
> The Hilltop Institute
> University of Maryland Baltimore County
>
> blobb wrote:
> > I am trying to build a recordset off of an entry on a form that "sounds like"
> > or is similiar to the current entry. I have the below code that was working
> > well last time I used it but I am now getting the "Data type mismatch error
> > in criteria expression". Could someone help me identify why this is? I have
> > tried double quotes, single quotes, no quotes...
> >
> > The "Soundex" is the function for the sounds like, [Crosswalk] is existing
> > table.
> >
> >
> > Dim rst As dao.Recordset
> > Dim strLast As String
> > Dim db As Database
> >
> > Set db = CurrentDb()
> >
> > 'If on a new row.
> > If (Me.NewRecord = True) Then
> > '...check for duplicate Lastnames.
> > If Not IsNothing(Me.LastName) Then
> > ' Open a recordset to look for duplicate Lastnames.
> > Set rst = CurrentDb.OpenRecordset("SELECT PTid, Lastname,
> > FirstName, SSN FROM " & _
> > "Crosswalk WHERE Soundex([Lastname]) = '" &
> > Soundex(Me.LastName) & "'")
> >
> > Thanks! blobb

>

 
Reply With Quote
 
John Spencer
Guest
Posts: n/a
 
      15th Jul 2009
How about me.LastName

I would check it with the following

IF Len(Trim(Me.LastName & vbNullString)) > 0 then
....

and not with IsNothing - is that a custom function or are you trying to do

If Not (Me.LastName is Nothing) Then ...
which will return true even if the VALUE property of Me.LastName is
Null or an empty string.


'====================================================
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'====================================================


blobb wrote:
> The last name is a required field -- there are no blanks. Any other ideas?
>
> "John Spencer" wrote:
>
>> It could be your soundex function is having a problem. Are there any records
>> in Crosswalk where LastName is null or a zero-length string? If so, do the
>> Soundex function handle those cases?
>>
>> You might try testing with
>> IIF(Len(LastName & "") = 0,"zxvq",LastName)
>> to force a "legal" value to be passed to the Soundex function.
>>
>> John Spencer
>> Access MVP 2002-2005, 2007-2009
>> The Hilltop Institute
>> University of Maryland Baltimore County
>>
>> blobb wrote:
>>> I am trying to build a recordset off of an entry on a form that "sounds like"
>>> or is similiar to the current entry. I have the below code that was working
>>> well last time I used it but I am now getting the "Data type mismatch error
>>> in criteria expression". Could someone help me identify why this is? I have
>>> tried double quotes, single quotes, no quotes...
>>>
>>> The "Soundex" is the function for the sounds like, [Crosswalk] is existing
>>> table.
>>>
>>>
>>> Dim rst As dao.Recordset
>>> Dim strLast As String
>>> Dim db As Database
>>>
>>> Set db = CurrentDb()
>>>
>>> 'If on a new row.
>>> If (Me.NewRecord = True) Then
>>> '...check for duplicate Lastnames.
>>> If Not IsNothing(Me.LastName) Then
>>> ' Open a recordset to look for duplicate Lastnames.
>>> Set rst = CurrentDb.OpenRecordset("SELECT PTid, Lastname,
>>> FirstName, SSN FROM " & _
>>> "Crosswalk WHERE Soundex([Lastname]) = '" &
>>> Soundex(Me.LastName) & "'")
>>>
>>> Thanks! blobb

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Data type mismatch in criteria expression even the datatype is the same John W. Vinson Microsoft Access Queries 0 10th Nov 2009 05:09 PM
Using the Build Criteria - Datatype Mismatch (Access 2k, DAO) Leonard Priestley Microsoft Access Form Coding 4 24th Oct 2005 09:55 AM
Mismatch data in criteria expression =?Utf-8?B?VEQxMQ==?= Microsoft Access Getting Started 1 3rd Feb 2005 09:40 PM
data type mismatch in criteria expression when no criteria specified JR Microsoft Access Queries 1 27th Jul 2004 03:47 AM
Re: data type mismatch in criteria expression John Spencer (MVP) Microsoft Access Queries 0 8th Jul 2003 02:40 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:22 PM.