Run time error on SQL

aziz rasul

Active member
Local time
Today, 21:51
Joined
Jun 26, 2000
Messages
1,935
I have the following snippet of code: -

Code:
    strSQL = "SELECT " & strField & " from " & strTable & " WHERE " & strField & ">0 Order by " & strField & ";"
    Set rst = CurrentDb.OpenRecordset(strSQL)

On the last line I get error 13 i.e. 'Type mismatch'. Any ideas why this should be?

Even if I write

strSQL = "SELECT AdmissionLOS from StrokeLOSDATA;"
 
Last edited:
The fieldname that is stored in strField is probably a text field, not a number...
 
strField is a Number data type i.e. Double.

Sorry to hear about your sister-in-law.
 
Last edited:
Here's the heading of the function

Function Median(strTable As String, strField As String) As Single
 
strField is a string, or at least you are passing it to the function as a string so if in the field is a double datatype then you need to use the following:

Code:
    strSQL = "SELECT " & strField & " from " & strTable & " WHERE " & cdbl(strField) & ">0 Order by " & strField & ";"
    Set rst = CurrentDb.OpenRecordset(strSQL)
 
I got the same error message but on the strSQL line rather than the Set rst line.
 
Just a thought. Is Rst an DAO or ADODB.recordset?
try this:
Code:
Dim rst as DAO.Recordset
If you have references to ADO and DAO, it is possible to select the wrong Recordset object in the DIM statement.

HTH,
Chris
 
Then either the DAO thing that Wilkinson said (Hey of the razors?? LOL How many times do you get that question?? )

Or we need more info on the complete coding around this problem.
 
This was worrying me for a while. You guys were right. When I typed dao, it didn't automatically change it to DAO. I looked at Tools|References and the DAO library was not selected. On my smaller version where I initially tested it, it did have the DAO library.

Thanks a bunch guys.
 

Users who are viewing this thread

Back
Top Bottom