Consulting

Results 1 to 4 of 4

Thread: Solved: VBA-SQL Type Mismatch

  1. #1

    Solved: VBA-SQL Type Mismatch

    Hello, anytime I try to run this code:

    [VBA]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[/VBA]

    I get a type mismatch error at

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

    Any ideas?

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

    Thanks,

    Maestro.

  2. #2
    VBAX Expert Imdabaum's Avatar
    Joined
    Jun 2006
    Posts
    652
    Location
    [VBA]
    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
    [/VBA]
    Someday I'll understand everything...
    Even then...I'll still pretend I'm a beginner.

  3. #3
    VBAX Mentor
    Joined
    Feb 2009
    Posts
    447
    Location
    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:

    [VBA]Dim applicationRst As DAO.Recordset[/VBA]

  4. #4

    THANKS!

    Thanks guys!, it worked!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •