You should always clean down objects that are owned by the form - so if your 'db' object is private to that form then the unload code would work (Well, you might just want to change it to :


If Not db is nothing then
db.Close
set db = nothing
End if




- as the form is already unloading (hence the unload event) you want to make sure that it cleans up it's objects).


If you've declared the 'db' object as public in the form, then you could be in trouble. If another form / public object in your project has a reference to the 'db' object, then the form will never really be unloaded until all references to that object are cleared.

It's also worthwile doing the following when Unloading forms :


Unload frmSomeForm
set frmSomeForm = nothing




The second line clears down the memory used by VB (it still keeps any static variables in the form in memory when the form has been unloaded). Setting the frmSomeForm to nothing gets around this limitation / 'feature' of VB.

Chris Eastwood

CodeGuru - the website for developers
http://codeguru.developer.com/vb