Currentdb.OpenRecordset fun

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matt Parkins

    #1

    Currentdb.OpenRecordset fun

    I think I may have lost the plot. Just a few years ago I'm sure I wrote
    something similar to the following code:

    dim rst as recordset
    set rst = currentdb.openr ecordset("mytab le")

    ' blah blah blah

    rst.close

    I'm sure this should work now, but it doesn't.. When I run it I get a type
    mismatch on the second line (set rst.. etc). Perhaps this might be a
    missing reference? Currently selected references for the project are:

    Visual Basic for Applications
    Microsoft Access 10.0 Object library
    OLE automation
    Microsoft ActiveX Data Objects 2.1 Library
    Microsoft DAO 3.6 object library

    I think it's the last one that should enable the code to work (is currentdb
    part of DAO object library?) Or am I missing a reference? Any ideas what
    is going on? I'm sure the code should work.. !

    Thanks in advance.

    Matt






  • Allen Browne

    #2
    Re: Currentdb.OpenR ecordset fun

    Matt, the trouble is that both the DAO library and the ADO library have a
    Recordset object.

    You have listed the ADO library above DAO, so you get an ADO recordset from:
    dim rst as recordset
    When you try to assign a DAO recordset to it, it fails.

    The solution is to be explicit about which recordset you want, i.e.:
    dim rst as DAO.recordset

    --
    Allen Browne - Microsoft MVP. Perth, Western Australia.
    Tips for Access users - http://allenbrowne.com/tips.html

    "Matt Parkins" <matt@NOSPAMPRE TTYPLEASEparkin s.uk.net> wrote in message
    news:OIg5b.9111 $_e2.6549@news-binary.blueyond er.co.uk...[color=blue]
    > I think I may have lost the plot. Just a few years ago I'm sure I wrote
    > something similar to the following code:
    >
    > dim rst as recordset
    > set rst = currentdb.openr ecordset("mytab le")
    >
    > ' blah blah blah
    >
    > rst.close
    >
    > I'm sure this should work now, but it doesn't.. When I run it I get a[/color]
    type[color=blue]
    > mismatch on the second line (set rst.. etc). Perhaps this might be a
    > missing reference? Currently selected references for the project are:
    >
    > Visual Basic for Applications
    > Microsoft Access 10.0 Object library
    > OLE automation
    > Microsoft ActiveX Data Objects 2.1 Library
    > Microsoft DAO 3.6 object library
    >
    > I think it's the last one that should enable the code to work (is[/color]
    currentdb[color=blue]
    > part of DAO object library?) Or am I missing a reference? Any ideas what
    > is going on? I'm sure the code should work.. ![/color]


    Comment

    • Matt Parkins

      #3
      Re: Currentdb.OpenR ecordset fun

      YES! Thanks, that worked! Spot on!

      Thanks man.

      Matt

      "Allen Browne" <abrowne1_SpamT rap@bigpond.net .au> wrote in message
      news:nkh5b.7978 7$bo1.34153@new s-server.bigpond. net.au...[color=blue]
      > Matt, the trouble is that both the DAO library and the ADO library have a
      > Recordset object.
      >
      > You have listed the ADO library above DAO, so you get an ADO recordset[/color]
      from:[color=blue]
      > dim rst as recordset
      > When you try to assign a DAO recordset to it, it fails.
      >
      > The solution is to be explicit about which recordset you want, i.e.:
      > dim rst as DAO.recordset
      >
      > --
      > Allen Browne - Microsoft MVP. Perth, Western Australia.
      > Tips for Access users - http://allenbrowne.com/tips.html
      >
      > "Matt Parkins" <matt@NOSPAMPRE TTYPLEASEparkin s.uk.net> wrote in message
      > news:OIg5b.9111 $_e2.6549@news-binary.blueyond er.co.uk...[color=green]
      > > I think I may have lost the plot. Just a few years ago I'm sure I wrote
      > > something similar to the following code:
      > >
      > > dim rst as recordset
      > > set rst = currentdb.openr ecordset("mytab le")
      > >
      > > ' blah blah blah
      > >
      > > rst.close
      > >
      > > I'm sure this should work now, but it doesn't.. When I run it I get a[/color]
      > type[color=green]
      > > mismatch on the second line (set rst.. etc). Perhaps this might be a
      > > missing reference? Currently selected references for the project are:
      > >
      > > Visual Basic for Applications
      > > Microsoft Access 10.0 Object library
      > > OLE automation
      > > Microsoft ActiveX Data Objects 2.1 Library
      > > Microsoft DAO 3.6 object library
      > >
      > > I think it's the last one that should enable the code to work (is[/color]
      > currentdb[color=green]
      > > part of DAO object library?) Or am I missing a reference? Any ideas[/color][/color]
      what[color=blue][color=green]
      > > is going on? I'm sure the code should work.. ![/color]
      >
      >[/color]


      Comment

      • Mark Lewin

        #4
        Re: Currentdb.OpenR ecordset fun

        Matt Parkins wrote:[color=blue]
        > I think I may have lost the plot. Just a few years ago I'm sure I wrote
        > something similar to the following code:
        >
        > dim rst as recordset
        > set rst = currentdb.openr ecordset("mytab le")
        >
        > ' blah blah blah
        >
        > rst.close
        >
        > I'm sure this should work now, but it doesn't.. When I run it I get a type
        > mismatch on the second line (set rst.. etc)[/color]


        Hi Matt

        Now Access is becoming more ADO-ish, I think you need to be more
        specific about what type of recordset you use. Try this:

        dim rst as DAO.recordset
        set rst = currentdb.openr ecordset("mytab le")

        ' blah blah blah

        rst.close

        Hope this helps.

        Mark


        Comment

        • johnhrschuster
          New Member
          • Mar 2006
          • 2

          #5
          Happened to me

          Move the DAO reference above the ADO reference and the problem should go away. You are using a DAO chunk of code and the ADO is trying to run it.

          Originally posted by Matt Parkins
          I think I may have lost the plot. Just a few years ago I'm sure I wrote
          something similar to the following code:

          dim rst as recordset
          set rst = currentdb.openr ecordset("mytab le")

          ' blah blah blah

          rst.close

          I'm sure this should work now, but it doesn't.. When I run it I get a type
          mismatch on the second line (set rst.. etc). Perhaps this might be a
          missing reference? Currently selected references for the project are:

          Visual Basic for Applications
          Microsoft Access 10.0 Object library
          OLE automation
          Microsoft ActiveX Data Objects 2.1 Library
          Microsoft DAO 3.6 object library

          I think it's the last one that should enable the code to work (is currentdb
          part of DAO object library?) Or am I missing a reference? Any ideas what
          is going on? I'm sure the code should work.. !

          Thanks in advance.

          Matt

          Comment

          Working...