ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Type Mismatch Error when running a SELECT SQL (https://www.excelbanter.com/excel-programming/322724-type-mismatch-error-when-running-select-sql.html)

Andy Dorph

Type Mismatch Error when running a SELECT SQL
 
I am getting a Type Mismatch error (Error 13) occurring when I run the
following code. The Set rs statement is what is highlighted. The query
string works when I go into Design Query and paste it in the Edit SQL window.

With the exception of P_ID, all fields in the table are text fields. P_ID
is am AutoNumber field. When I display the query in a msgBox, There are no
quotes or tics around the value stored in strRecNo (as it should be). I have
used this same template for all the other select statements I am executing
with no problems.

Is there something I am missing? Any help would be appreciated.

TIA


Dim rs As Recordset

strProjectQuery = "SELECT P_FUND, P_BORG, P_NAME, P_2120, P_2125 " & _
"FROM Projects " & _
"WHERE P_ID=" & _
strRecNo & ";"

Set rs = CurrentDb().OpenRecordset(strProjectQuery)

Rob Bovey

Type Mismatch Error when running a SELECT SQL
 
Hi Andy,

If you declare your Recordset variable like this:

Dim rs As DAO.Recordset

Does that solve your problem? If so you most likely have the Microsoft
ActiveX Data Objects type library referenced in your project.

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm

"Andy Dorph" wrote in message
...
I am getting a Type Mismatch error (Error 13) occurring when I run the
following code. The Set rs statement is what is highlighted. The query
string works when I go into Design Query and paste it in the Edit SQL
window.

With the exception of P_ID, all fields in the table are text fields. P_ID
is am AutoNumber field. When I display the query in a msgBox, There are
no
quotes or tics around the value stored in strRecNo (as it should be). I
have
used this same template for all the other select statements I am executing
with no problems.

Is there something I am missing? Any help would be appreciated.

TIA


Dim rs As Recordset

strProjectQuery = "SELECT P_FUND, P_BORG, P_NAME, P_2120, P_2125 " & _
"FROM Projects " & _
"WHERE P_ID=" & _
strRecNo & ";"

Set rs = CurrentDb().OpenRecordset(strProjectQuery)





All times are GMT +1. The time now is 05:16 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com