By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,483 Members | 1,939 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,483 IT Pros & Developers. It's quick & easy.

Type Mismatch Error in Recordset Where Clause

P: n/a
Why do I receive a Type mismatch error when running the following
code, which has a SQL Server 2000 back end database?
The error occurs on the following line: Set rs = db.OpenRecordset(SQL,
dbOpenDynaset)
>
Dim db As DAO.Database
Dim rs As DA0.Recordset
Dim SQL As String
Dim CountRecs As Long

Set db = CurrentDb()

SQL = "SELECT tblProduct.ProductCode, tblProduct.Description "
SQL = SQL & "FROM tblProduct WHERE tblProduct.[ProductCode]=' " &
Me!
cboProductCode & " ' "

Set rs = db.OpenRecordset(SQL, dbOpenDynaset)
rs.Open
CountRecs = rs.RecordCount
<

Feb 15 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Feb 15, 5:42 pm, "tomleb...@msn.com" <tomleb...@msn.comwrote:
Why do I receive a Type mismatch error when running the following
code, which has a SQL Server 2000 back end database?
The error occurs on the following line: Set rs = db.OpenRecordset(SQL,
dbOpenDynaset)

Dim db As DAO.Database
Dim rs As DA0.Recordset
Dim SQL As String
Dim CountRecs As Long

Set db = CurrentDb()

SQL = "SELECT tblProduct.ProductCode, tblProduct.Description "
SQL = SQL & "FROM tblProduct WHERE tblProduct.[ProductCode]=' " &
Me!
cboProductCode & " ' "

Set rs = db.OpenRecordset(SQL, dbOpenDynaset)
rs.Open
CountRecs = rs.RecordCount
<

This may be obvious, but is the ProductCode field a string type?

Feb 16 '07 #2

P: n/a
On Feb 15, 5:42 pm, "tomleb...@msn.com" <tomleb...@msn.comwrote:
Why do I receive a Type mismatch error when running the following
code, which has a SQL Server 2000 back end database?
The error occurs on the following line: Set rs = db.OpenRecordset(SQL,
dbOpenDynaset)

Dim db As DAO.Database
Dim rs As DA0.Recordset
G0od 1

James A. Fortune
CD********@FortuneJames.com

Feb 16 '07 #3

P: n/a
On Feb 15, 4:52 pm, "storrboy" <storr...@sympatico.cawrote:
On Feb 15, 5:42 pm, "tomleb...@msn.com" <tomleb...@msn.comwrote:


Why do I receive a Type mismatch error when running the following
code, which has a SQL Server 2000 back end database?
The error occurs on the following line: Set rs = db.OpenRecordset(SQL,
dbOpenDynaset)
Dim db As DAO.Database
Dim rs As DA0.Recordset
Dim SQL As String
Dim CountRecs As Long
Set db = CurrentDb()
SQL = "SELECT tblProduct.ProductCode, tblProduct.Description "
SQL = SQL & "FROM tblProduct WHERE tblProduct.[ProductCode]=' " &
Me!
cboProductCode & " ' "
Set rs = db.OpenRecordset(SQL, dbOpenDynaset)
rs.Open
CountRecs = rs.RecordCount
<

This may be obvious, but is the ProductCode field a string type?- Hide quoted text -

- Show quoted text -
The ProductCode is text in a combo box, which I assume is a string.
Should another argument follow dbOpenDynaset because this is an SQL
Server database.

Feb 16 '07 #4

P: n/a
On Feb 16, 1:09 am, "tomleb...@msn.com" <tomleb...@msn.comwrote:
On Feb 15, 4:52 pm, "storrboy" <storr...@sympatico.cawrote:
On Feb 15, 5:42 pm, "tomleb...@msn.com" <tomleb...@msn.comwrote:
Why do I receive a Type mismatch error when running the following
code, which has a SQL Server 2000 back end database?
The error occurs on the following line: Set rs = db.OpenRecordset(SQL,
dbOpenDynaset)
Dim db As DAO.Database
Dim rs As DA0.Recordset
Dim SQL As String
Dim CountRecs As Long
Set db = CurrentDb()
SQL = "SELECT tblProduct.ProductCode, tblProduct.Description "
SQL = SQL & "FROM tblProduct WHERE tblProduct.[ProductCode]=' " &
Me!
cboProductCode & " ' "
Set rs = db.OpenRecordset(SQL, dbOpenDynaset)
rs.Open
CountRecs = rs.RecordCount
<
This may be obvious, but is the ProductCode field a string type?- Hide quoted text -
- Show quoted text -

The ProductCode is text in a combo box, which I assume is a string.
Should another argument follow dbOpenDynaset because this is an SQL
Server database.

As Mr.Fortune points out you have DA0 not the correct DAO in your
example.
A text box does not mean it's a string field. Do the ProductCodes
contain letters or are they all numeric?
Check the actual data type of the field in the table if you can and
see what it is.

Feb 17 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.