Silly DAO question...

David R

I know a few things...
Local time
Today, 02:44
Joined
Oct 23, 2001
Messages
2,633
If you're working in DAO and want to ensure your memory is being reclaimed properly, is there any purpose to this:
Set CurrentDb = Nothing

Note that I am not setting a reference variable to it since this is the only thing I am using it for. Does the simple act of calling it cause memory to be used wastefully? Here's a concrete example:
Code:
Public Function fGetLatestContact(CID As Long) As String
    Dim rstLastCon As DAO.Recordset
    
    Set rstLastCon = CurrentDb.OpenRecordset("SELECT TOP 1 [DateContacted] FROM tableContactDetails WHERE [ContactID] = " & CID & " ORDER BY [DateContacted] DESC", dbOpenSnapshot)
    If rstLastCon.RecordCount Then fGetLatestContact = rstLastCon!DateContacted
    Set rstLastCon = Nothing
End Function
 
No, you don't have to set CurrentDB to nothing, as far as I know.

It's not a variable that you've declared. It's a funciton that returns a database object. Setting the function to Nothing won't do anything (again, as far as I know).
 
David,

I agree with Peter, when the code is finished the lifetime of all
objects within its scope is finished.

I think this is just one of those "good" programming practices.

Do you need an Exit Sub before an End Sub?
Should you type LET x =5?

Who knows?

Wayne
 
Actually, you do need an Exit Sub in some cases

I discovered today that DoCmd.Close on a popup form doesn't keep your code from 'falling through' the rest of the form code. So if there's other code that may get triggered, your best bet may be to use DoCmd.Close followed by Exit Sub.
 
Last edited:
Thanks David,

I know, kind of like "falling" into your error handler with
no error.

See ya,
Wayne
 

Users who are viewing this thread

Back
Top Bottom