Results 1 to 2 of 2
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Public Object Variables Behavior in Access 2000

    Rory(Lounge moderator) told me that if one declares Public cat as New ADOX.catalog in a standard module in an Access 2000 project, then you one mustn't use set cat = nothing in any module's(standard or class)procedure "otherwise once you've run the procedure the public instance of the catalog will be destroyed and you won't be able to reference it in any procedure unless you create a new instance of it."
    Does the same philosophy(pun intended) work for all object variables declared as public?
    Because in the same module I've also declared Public rst as New ADODB.Recordset and use rst in two class modules associated with two reports: Report1 and Report2.
    In Private Sub Report_Close() for Report1 I put
    set rst = Nothing
    I opened and closed Report1 and opened Report2 immediately afterwards.
    According to what you say, since the Private Sub Report_Open(Cancel as Integer) for Report2 contains code such as
    rst.Open("Select Table.Id, ....
    I was expecting an error message telling that rst doesn't exist but, to my surprise, Sub Report_Open runs normally even though I didn't create a new instance of rst.
    Can anyone explain why?

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Public Object Variables Behavior in Access 2000

    You open a recordset object, so if you set it to nothing and then issue an open, it will happily open the same recordset object (note: that isn't necessarily the same recordset) without any argument. If you tried to reference the recordset object you had set to nothing without reinstantiating it with an Open method, you would have received an error.

    Catalog objects are used to get at the schema of a database, so if you need to keep using the same catalog, you shouldn't set it to nothing until it is no longer needed. If you do set it to nothing, then any objects that depend on it, like a table object for example, will be orphaned and broken.
    Charlotte

Posting Permissions

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