Recordset error

G

Guest

Hello,

I'm having a problem retreiving recordset, getting "Datatype mismatch in
criteria expression" Here's the code simplified:

Dim SQL As String
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset

SQL = "SELECT tblData.PartID FROM tblData " & _
"WHERE tblData.PartID=" & [Forms]![frmData]![txtPartID]

rst.Open SQL, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
MsgBox rst.RecordCount

What the code is suppose to do is to find how many records there are of a
specific part id (part id is a string expression, example "00535000V"). The
problem is that cannot search on a string criteria, e.g.
"[Forms]![frmData]![txtPartID]" the way I type the code.
Any suggestions on what I need to change in the SQL expression?

Thanx,

Isbjornen

PS. I've used similar code to search by number without any problems.
 
G

George Nicholson

Strings require single-quote delimiters.

"WHERE tblData.PartID= '" & [Forms]![frmData]![txtPartID] & "'"
 

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