Heenan, Lambert
Lambert.Heenan at AIG.com
Mon May 16 15:50:41 CDT 2005
Of course the correct way to do this kind of thing is to build a class to encapsulate the allegedly global data so that 'foreign objects' have to use the class interface to get at the data. The trouble is few people (John C excepted) seem to make any serious use of Access classes. Lambert -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Ken Ismert Sent: Monday, May 16, 2005 4:12 PM To: 'Access Developers discussion and problem solving' Subject: RE: [AccessD] Global Variable Globals are appropriate if the data they store is truly global in scope. So, things like Application Name and Current Login Name are proper candidates for globals. Problems can happen when data that is really local to some smaller context, like a form or report, is made global for programming convenience. This can quickly become the Acme "Shoot Yourself in the Foot" kit that Charlotte warns about: you start fighting synchronization issues (keeping local and global data consistent), other code changing your "local" global when you least expect it, dependencies on objects that may or may not be open and active, etc. Ideally, the data holder (the object with the local data) should TELL the foreign object what it needs to do its work. The foreign object shouldn't have to ASK or ASSUME. With a tell-style of data passing, synchronization becomes a non-issue, because the foreign object is given only what it needs to do its next task. Other code or objects not party to the conversation can't interfere by unexpectedly changing data. Lastly, this style of decoupled data passing allows the foreign object to be driven by any data holder, enhancing flexibility and reducing dependencies. Unfortunately, Access does all it can to encourage bad programming practice (case in point: the [Forms]![Form]![Control] syntax, a classic "ask" construct). And it's "tell" constructs, like OpenArgs, are insufficient for any but the simplest data passing needs. Most veteran programmers, through hard experience, grasp this issue and come up with better data passing schemes to work around it. Still, there seems to be no commonly accepted way to "do it right", and it remains a stumbling block for the novice. -Ken