Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Nov 2001
    Thanked 0 Times in 0 Posts

    Set rst = dbs.OpenRecordset(sqlstr) PROBLEM (2000)

    My database loops through all the text files in a series of folders and extracts information from them which I want to load into a table.

    All works fine, and all the info I want is assigned to appropriate variables. Now I want to save the info in the variables into the 'rshead' table.

    I use the code:

    dim sqlstr, dbs As Database, rst As Recordset, caseid, rscatgy

    sqlstr = "select * from rshead" 'which is initially empty
    Set dbs = CurrentDb
    Set rst = dbs.OpenRecordset(sqlstr)
    With rst
    !Case_ID = caseid
    End With

    Problem is, the code spits the dummy at "Set rst = dbs.OpenRecordset(sqlstr)" and tells me I have a type mismatch (error 13).

    Why is this?

    If you can help, I'd appreciate it.

    Thanks in advance.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Thanked 28 Times in 28 Posts

    Re: Set rst = dbs.OpenRecordset(sqlstr) PROBLEM (2000)

    In Access 2000, the default data model is ADO. You want a DAO recordset here, so try

    Dim rst As DAO.Recordset

    instead of

    Dim rst As Recordset

    Make sure that the DAO library is set in Tools/References...

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Sacramento, California, USA
    Thanked 1 Time in 1 Post

    Re: Set rst = dbs.OpenRecordset(sqlstr) PROBLEM (2000)

    In addition to Hans's suggestion of declaring your recordset and database as DAO.recordset and DAO.Database, you probably need to declare your strSQL as a string rather than a variant and you need to add the dbOpenDynaset argument to the OpenRecordset method. Otherwise, you won't be able to edit that recordset.

    As an aside, it isn't a good idea to declare variables as variants unless you specifically need a variant. Otherwise, you're just wasting resources and you can get unexpected type mismatches when the code is expecting a particular datatype.

Posting Permissions

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