PDA

View Full Version : Solved: VBA-SQL Type Mismatch



maestro_01
08-24-2010, 01:05 PM
Hello, anytime I try to run this code:

Public Function addNoneApplication()
Dim applicationRst As Recordset
Set applicationRst = CurrentDb.OpenRecordset("SELECT Application.Application_ID, Application.Application_Name " & _
"FROM Application")
applicationRst.AddNew
applicationRst(0) = -1
applicationRst(1) = "None"
applicationRst.Update
End Function

I get a type mismatch error at

Set applicationRst = CurrentDb.OpenRecordset("SELECT Application.Application_ID, Application.Application_Name " & _
"FROM Application")

Any ideas?

I have Option Compare Database set at the beginning of the module.

Thanks,

Maestro.

Imdabaum
08-24-2010, 01:56 PM
Public Function addNoneApplication()
Dim applicationRst As Recordset
Set applicationRst = CurrentDb.OpenRecordset("SELECT Application.Application_ID, Application.Application_Name " & _
"FROM Application")
applicationRst.AddNew
applicationRst.Fields(0) = -1
applicationRst.Fields(1) = "None"
applicationRst.Update
End Function

hansup
08-24-2010, 09:53 PM
If your application has a reference set for ADO with a higher priority than DAO, your DIM statement for the recordset might be interpreted as the wrong type of recordset.

It has to be a DAO recordset for CurrentDb.OpenRecordset, so declare it that way explicitly in your DIM statement:

Dim applicationRst As DAO.Recordset

maestro_01
08-25-2010, 01:06 PM
Thanks guys!, it worked!