Persistent recordset error 91

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bill R via AccessMonster.com

    #1

    Persistent recordset error 91


    I get the error msg "Object variable or With block variable not set" when
    closing the "persistent " recordset I opened when the application opened.

    I have the rs variable declared in the declarations section of a module:

    Public rsAlwaysOpen As DAO.Recordset


    Then, when the switchboard form loads I set the variable:

    Dim dbs As DAO.Database

    Set dbs = CurrentDb
    Set rsAlwaysOpen = dbs.OpenRecords et("tblGlobals" )

    Presumably, the rs will now stay open until I close it in the Unload or Close
    event of the switchboard form, but, instead, I get the above error and the rs
    appears to be closed (I can't get any values in the Immediate window).

    It's only a problem if I open the db with the shift key. Users don't get any
    such msgs.

    Bill


    --
    Message posted via AccessMonster.c om

  • Wayne Morgan

    #2
    Re: Persistent recordset error 91

    There is a KB article on this. If the dbs goes out of scope, then you may
    also lose the subsequent object variables as well. The example you give
    isn't exactly the same as the article, but I suspect the problem is the same
    one.



    --
    Wayne Morgan
    MS Access MVP


    "Bill R via AccessMonster.c om" <forum@AccessMo nster.com> wrote in message
    news:51DD9C801C 1E8@AccessMonst er.com...[color=blue]
    >
    > I get the error msg "Object variable or With block variable not set" when
    > closing the "persistent " recordset I opened when the application opened.
    >
    > I have the rs variable declared in the declarations section of a module:
    >
    > Public rsAlwaysOpen As DAO.Recordset
    >
    >
    > Then, when the switchboard form loads I set the variable:
    >
    > Dim dbs As DAO.Database
    >
    > Set dbs = CurrentDb
    > Set rsAlwaysOpen = dbs.OpenRecords et("tblGlobals" )
    >
    > Presumably, the rs will now stay open until I close it in the Unload or
    > Close
    > event of the switchboard form, but, instead, I get the above error and the
    > rs
    > appears to be closed (I can't get any values in the Immediate window).
    >
    > It's only a problem if I open the db with the shift key. Users don't get
    > any
    > such msgs.
    >
    > Bill
    >
    >
    > --
    > Message posted via AccessMonster.c om
    > http://www.accessmonster.com/Uwe/For...ccess/200507/1[/color]


    Comment

    • Bill R via AccessMonster.com

      #3
      Re: Persistent recordset error 91


      Wayne,

      Thanks for your suggestion, but if I understand the article correctly, it
      would appear that my code already implements their suggested solution.
      I set currentdb to a variable, dbs, and then assign my rs to a dbs.
      openrecordset table.

      Bill

      Wayne Morgan wrote:[color=blue]
      >There is a KB article on this. If the dbs goes out of scope, then you may
      >also lose the subsequent object variables as well. The example you give
      >isn't exactly the same as the article, but I suspect the problem is the same
      >one.
      >
      >http://support.microsoft.com/default...b;en-us;200592
      >[color=green]
      >> I get the error msg "Object variable or With block variable not set" when
      >> closing the "persistent " recordset I opened when the application opened.[/color]
      >[quoted text clipped - 21 lines][color=green]
      >>
      >> Bill[/color][/color]


      --
      Message posted via http://www.accessmonster.com

      Comment

      • bruce@aristotle.net

        #4
        Re: Persistent recordset error 91

        I suspect that Wayne is correct in that the problem is that the
        database variable you're using (dbs) goes out of scope but I don't
        think CurrentDB has anything to do with it. See VBA help on the
        Recordset object:

        "Note If you use variables to represent a Recordset object and the
        Database object that contains the Recordset, make sure the variables
        have the same scope, or lifetime. For example, if you declare a public
        variable that represents a Recordset object, make sure the variable
        that represents the Database containing the Recordset is also public,
        or is declared in a Sub or Function procedure using the Static
        keyword."

        If I were you I'd declare a public database variable and keep my
        recordsets private or static.

        HTH,
        Bruce

        Comment

        • Wayne Morgan

          #5
          Re: Persistent recordset error 91

          I suspect the problem is that your "rst" variable is global but your "dbs"
          variable is only valid in the procedure where it runs. When that procedure
          is done, "dbs" goes out of scope and you lose the value of "rst" at the same
          time.

          --
          Wayne Morgan
          MS Access MVP


          "Bill R via AccessMonster.c om" <forum@AccessMo nster.com> wrote in message
          news:51E6343D67 F28@AccessMonst er.com...[color=blue]
          >
          > Wayne,
          >
          > Thanks for your suggestion, but if I understand the article correctly, it
          > would appear that my code already implements their suggested solution.
          > I set currentdb to a variable, dbs, and then assign my rs to a dbs.
          > openrecordset table.[/color]


          Comment

          • Bill R via AccessMonster.com

            #6
            Re: Persistent recordset error 91


            AHA! Comes the dawn..

            Well. I tried makeing both the rs and dbs public, but I'm still getting the
            same msg. But, I'm sure I'm on the right track now. I'll let you know how I
            make out.

            Bill

            Bill R wrote:[color=blue]
            >Wayne,
            >
            >Thanks for your suggestion, but if I understand the article correctly, it
            >would appear that my code already implements their suggested solution.
            >I set currentdb to a variable, dbs, and then assign my rs to a dbs.
            >openrecordse t table.
            >
            >Bill
            >[color=green]
            >>There is a KB article on this. If the dbs goes out of scope, then you may
            >>also lose the subsequent object variables as well. The example you give[/color]
            >[quoted text clipped - 8 lines][color=green][color=darkred]
            >>>
            >>> Bill[/color][/color][/color]


            --
            Message posted via AccessMonster.c om

            Comment

            • Bill R via AccessMonster.com

              #7
              Re: Persistent recordset error 91


              Got it!

              I had my code in the unload or close event of the form. Unfortunately, those
              events take place after a docmd.quit command in a cmd button on the same form.
              So by the time my code ran, the db was already closed, although intuition
              would argue against that, given that the event code is still running in the
              db that is closed.

              Thanks for pointing me in the right direction.

              Bill


              --
              Message posted via AccessMonster.c om

              Comment

              • bruce@aristotle.net

                #8
                Re: Persistent recordset error 91

                Actually, DoCmd.Quit shuts down Access immediately. Once this command
                has executed, no other lines in the event procedure will be processed,
                nor will control be passed back to any calling routine. Everything
                simply stops, right then and there.

                Bruce

                Comment

                Working...