CurrentDB.OpenRecordset and memory

  • Thread starter Thread starter Mark A. Sam
  • Start date Start date
M

Mark A. Sam

Hello,

Is there any memory issue with using the format:

Dim rst as Recordset
Set rst = CurrentDB.OpenRecordset("RecordSet Name",dbOpenDynaset)

some code

Set rst = Nothing


as opposed to setting a Database Variable then setting that Variable to
Nothing at the end of the procedure, like:

Dim dbs as Database
Dim rst as Recordset
Set rst = dbs.OpenRecordset("RecordSet Name",dbOpenDynaset)

Some code

Set rst = Nothing
Set dbs = Nothing

Thanks and God Bless,

Mark A. Sam
 
There was a sublte difference depending on the line that you ommited in the
second example. What are you setting dbs to? currentdb or dbengine(0)(0)??
 
Just to expand slightly. .. .

The CurrentDb syntax creates another instance of the current project's
database, but the DBEngine syntax refers to the open copy of the current
database.

therefore if dbs is set to dbengine(0)(0) it's more efficient that currentdb
 
John,

I would be setting dbs = CurrentDb.

My issue is with memory. If I use one method over the other, is there an
advantage for memory management?

For example, I had a method in the Timer event of a form which checked the
value of a field in a table and updated it if necessary. The Timer fired
every 10 seconds and I ranout of memory quickly and had to close the app. I
changed my method and placed the procedure in the Current event, but it got
me wondering if I could be more efficient since I use DAO a lot in this
application.

Thanks

Mark
 
Mark said:
Is there any memory issue with using the format:

Dim rst as Recordset
Set rst = CurrentDB.OpenRecordset("RecordSet Name",dbOpenDynaset)

some code

Set rst = Nothing

I **think** this is most efficient (both speed and memory),
even if it's probably not noticeable.

Set rst = DbEngine(0)(0).OpenRecordset( . . .

But, I would make sure to close that recordset to reclaim
any memory it may be consuming:
rst.Close : Set rst = Nothing
 
Back
Top