run-time error 13: type mismatch

spinkung

Registered User.
Local time
Today, 13:06
Joined
Dec 4, 2006
Messages
267
Morning,

I am trying to run an t-sql statement in my vb and put it in a recordset but when i try to put it in rs2 (my recordset object) i get a 'type mismatch' error.

The red highlighted text is where the error occurs. Can anyone see why??

Code:
sql = "SELECT * FROM [Serial Tracked Stockcodes] WHERE [Serial Tracked Stockcodes].[Stockcode] = '" & stk & "'"
[COLOR="Red"]Set rs2 = CurrentDb.OpenRecordset(sql)[/COLOR]

This is the debug.print result.....
Code:
SELECT * FROM [Serial Tracked Stockcodes] WHERE [Serial Tracked Stockcodes].[Stockcode] = 'UKB000518'


Thanks,
Spinkung.
 
arhhhgggghghhh, sorry folks. just me being a tit.

i had only declared:
'dim rs2 as Recordset'

when i needed:
'dim rs2 as DAO.Recordset'

if someone wants top tell me WHY i have to do this i would be grateful.

Many Thanks,
sorry for wasting anyones time.
 
It might have to to do with disambiguation.
Code:
'Ambiguous 
Dim rst As Recordset

'Disambiguated
Dim rst As DAO.Recordset

Not sure if this is your problem. but if you have both ADO and DAO selected in your references, you need to tell Access which type of recordset you are wanting to use.

Code:
'DAO
Dim rst as DAO.Recordset

'ADO
Dim rst As ADODB.Recordset
I could be wrong, but I think that you can actually speed up you code a little if you disambiguate. Maybe an MS Access guru can set the record straight on that.
 

Users who are viewing this thread

Back
Top Bottom