So what does a developer do when he can’t sleep at 3am? He decides to write an article about self-healing object variables!
So What Are Self-Healing Object Variables?
In plain English, these are variables that are intelligent enough that they initialize themselves once and retain their value for the entire session. If reset, they will reinitialize again automatically. They are like Global Variables on steroids. It is just one more step you can take as a developer to improve the overall performance and give your application a little boost, and this for any VBA application (not just Access)!
My first recollection of being exposed to the concept was back in, I believe 2003-2005ish, by MVP Dirk Goldgar who was answering one of my Access question in a discussion forum. He didn’t call it SHOV, but that is effectively what it was. Implementing it drastically helped with performance with a database I was struggling with, and from then on I was hooked! No clue who originally came up with the idea, and it may be taken from another programming language for all I know, but it’s been around for a long time.
Why Do We Want To Use Self-Healing Object Variables?
When we talk about Object Variables, we are most often talking about the use of the CreateObject() function, or in the case of Access specifically the use of CurrentDb. So things like
Set oExcel = CreateObject("Excel.Application")
Or
Set db= CurrentDb
These actions are straining, especially when done repetitively. The process of creating ActiveX reference, by using commands like CreateObject(), can cause significant delays, so we want to minimize such activities as much as possible to give the best user experience possible.
The idea behind Self-Healing Variables is you do it once, but hold it in memory that way subsequent calls don’t need to perform the initialization again, as it is still already in memory from the 1st call, ready to go.
Using Self-Healing variables can simplify your code since you no longer need to initialize such variables in your code and can significantly improve overall performance. On slower machines the performance boost achieved by using self-healing variables can be quite noticeable.
Continue reading →