data-type mismatch in criteria expression (querying autonumber field)

T

Todd

HI there, the following code is returning the error, data-
type mismatch in criteria expression. I assume that my
Autonumber field has a diferent kind of datatype ? Can I
base criteria on that field? HELP.

Dim strsql As String
Dim findthis As Integer
Dim db As Database
Call CurrentDb.Execute("delete * from tbltemp2")
findthis = Me.Text70
If IsNull(findthis) Then
MsgBox "You must Enter an IPR into the Field To Search for
it.", vbCritical, "Search"
Exit Sub
Else
Set db = CurrentDb
strsql = "INSERT INTO tbltemp2 (IPRNumber, firstname,
lastname, address, account_number) Select tblhistory.
[aunIPRNumber], tblHistory.[strcustomernamefirst],
tblhistory.[strcustomernamelast], tblhistory.
[strcustomeraddress], tblhistory.[straccountnumber] " & _
"FROM tblHistory " & _
"WHERE tblHistory.[aunIPRNumber]= '" & findthis & "'"
Call CurrentDb.Execute(strsql)

Thanks.
Todd
 
G

George Nicholson

"WHERE tblHistory.[aunIPRNumber]= '" & findthis & "'"

is ok *IF* aunIPRNumber is a text field. If it is indeed a number field,
you should use

"WHERE tblHistory.[aunIPRNumber]= " & findthis
 
T

Todd

Thanks George, it works now. Why the difference in Text
and Numbers ?
Todd
-----Original Message-----

"WHERE tblHistory.[aunIPRNumber]= '" & findthis & "'"

is ok *IF* aunIPRNumber is a text field. If it is indeed a number field,
you should use

"WHERE tblHistory.[aunIPRNumber]= " & findthis

--
George Nicholson

Remove 'Junk' from return address.


HI there, the following code is returning the error, data-
type mismatch in criteria expression. I assume that my
Autonumber field has a diferent kind of datatype ? Can I
base criteria on that field? HELP.

Dim strsql As String
Dim findthis As Integer
Dim db As Database
Call CurrentDb.Execute("delete * from tbltemp2")
findthis = Me.Text70
If IsNull(findthis) Then
MsgBox "You must Enter an IPR into the Field To Search for
it.", vbCritical, "Search"
Exit Sub
Else
Set db = CurrentDb
strsql = "INSERT INTO tbltemp2 (IPRNumber, firstname,
lastname, address, account_number) Select tblhistory.
[aunIPRNumber], tblHistory.[strcustomernamefirst],
tblhistory.[strcustomernamelast], tblhistory.
[strcustomeraddress], tblhistory.[straccountnumber] " & _
"FROM tblHistory " & _
"WHERE tblHistory.[aunIPRNumber]= '" & findthis & "'"
Call CurrentDb.Execute(strsql)

Thanks.
Todd


.
 
G

George Nicholson

When constructing an SQL statement, text criteria are expected to be
enclosed in quotes, number criteria are not. Your original code contained
the equivalent of:

WHERE aunIPRNumber = 'mynumber' (note the single quotes)

but, assuming aunIPRNumber contained numerical values, you needed it to be:

WHERE aunIPRNumber = mynumber (no quotes)

--
George Nicholson

Remove 'Junk' from return address.


Todd said:
Thanks George, it works now. Why the difference in Text
and Numbers ?
Todd
-----Original Message-----

"WHERE tblHistory.[aunIPRNumber]= '" & findthis & "'"

is ok *IF* aunIPRNumber is a text field. If it is indeed a number field,
you should use

"WHERE tblHistory.[aunIPRNumber]= " & findthis

--
George Nicholson

Remove 'Junk' from return address.


HI there, the following code is returning the error, data-
type mismatch in criteria expression. I assume that my
Autonumber field has a diferent kind of datatype ? Can I
base criteria on that field? HELP.

Dim strsql As String
Dim findthis As Integer
Dim db As Database
Call CurrentDb.Execute("delete * from tbltemp2")
findthis = Me.Text70
If IsNull(findthis) Then
MsgBox "You must Enter an IPR into the Field To Search for
it.", vbCritical, "Search"
Exit Sub
Else
Set db = CurrentDb
strsql = "INSERT INTO tbltemp2 (IPRNumber, firstname,
lastname, address, account_number) Select tblhistory.
[aunIPRNumber], tblHistory.[strcustomernamefirst],
tblhistory.[strcustomernamelast], tblhistory.
[strcustomeraddress], tblhistory.[straccountnumber] " & _
"FROM tblHistory " & _
"WHERE tblHistory.[aunIPRNumber]= '" & findthis & "'"
Call CurrentDb.Execute(strsql)

Thanks.
Todd


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top