View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Jamie Collins Jamie Collins is offline
external usenet poster
 
Posts: 593
Default Can DB connection retain throughout the Excel working session ?


Eric Fung wrote:
1. Does the Friend property safer in terms of security ?


I try to use the minimum scope possible e.g. if the connection isn't
required outside of the VBA project then don't expose it via a public
property/variable. Security isn't really a consideration here because
an Excel workbook's VBA project isn't secure enough to contain
sensitive information.

2. Although I see when the workbook is close, Office will help to

close the
connection for me.
I hope to be more discipline, to close the connection by myself
explicitly
However, I've tried to code at ThisWorkbook event - "BeforeClose"
and "Deactivate",
either event seems happen after Office already close the
connection for me.


I'd use the _BeforeClose event, with the extra code required to handle
the situation where the user cancels a save and therefore cancels the
close. Module level variables in the ThisWorkbook code module should
still be in scope (i.e. should not have been garbage-collected) when
the _BeforeClose and _Deactivate events fire, unless something has
happened to reset the VBA project e.g. hitting the reset button in the
Visual Basic Editor, adding controls to a worksheet, etc.

Jamie.

--