Results 1 to 6 of 6

Thread: DAO error (A2K)

  1. #1
    Star Lounger
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    DAO error (A2K)

    I have programmed with DAO and its precursors for a long time, but I continue to occasionally get an error that drives me crazy -- can anyone explain why this occurs? The code looks like this:

    dim db as Database
    dim rst as Recordset
    set db = CurrentDB
    set rst = db.OpenRecordset("ImportTable", dbOpenDynaset)

    This code often works for me, but on occasion I will get an error on this last statement: "type mismatch".

    Why? Is there a reference I need to include that I don't know about? I have been including the DAO 3.6 library, I thought that was sufficient. I would appreciate any insights, because I need DAO and this stops me dead in the water.

  2. #2
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: DAO error (A2K)

    Does this help ?

    <pre>Dim db As DAO.Database
    Dim rst As DAO.Recordset</pre>


  3. #3
    Star Lounger
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: DAO error (A2K)

    I always laugh when the simple answers clear up big headaches -- Thanks! That's been plaguing me off and on for years. Funny thing is, it often works without this fix -- like Access With Attitude.
    Now on to debug the next glitch...

  4. #4
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: DAO error (A2K)

    You're welcome, glad to help.

    It's a little tip from Hans, Always try to declare everything explicitly and always have:

    <pre>Option Explicit
    Option Compare Database</pre>


    At the top of each form which contains code, it clears all kinds of problems. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  5. #5
    4 Star Lounger SteveH's Avatar
    Join Date
    Jan 2001
    Location
    Chelsea, Gtr London, United Kingdom
    Posts
    587
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: DAO error (A2K)

    The reason it works sometimes and not others is dependent on whether you have the ADO library reference set and whether the ADO reference is above the DAO reference in the list. Explicitly declaring the Recordset as a DAO.Recordset avoids the problem because Access isn't guessing what is required.
    Steve H
    IT Lecturer/Access Developer
    O2K SR3/O2010; Win7Pro

  6. #6
    Star Lounger
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: DAO error (A2K)

    That did the trick, thank you.

Posting Permissions

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