Unanswered: Running with a missing library reference
OK, so I've written an Access application (using 2007) that works with Outlook to send and receive emails. It works nicely - of course, I had to add a Reference to the "Microsoft Outlook 12.0 Object Library".
My problem is getting this application to work in a multiuser environment, where not all of the computers have Outlook installed. Of course, I don't expect the non-Outlook computers to be able to actually do any emailing: there is a data item which is the name of the computer which is the "Emailer", and only that computer will attempt to talk to Outlook - the others don't even try. If they want to initiate an email out, they just shove the details in a table to be picked up later by the "Emailer" machine.
My problem is that the code includes many references to Outlook data types - and the mere presence of the declarations is enough to make Access fail (error 2950), even if no code that is using those data types is actually being executed.
If I try to run a version of the program with everything included on a machine that doesn't have Outlook 2007 installed, it fails with an error 2950 as soon as it tries to do anything interesting.
I could of course make two versions of my program - one with everything in, and another with all of the Outlook references removed. This would create a horrible maintenance problem which I'd much rather avoid if I can. Just think - I'd need to stub out all of the outlook-referencing routines so that the (unused) references to them in other code won't fail for a missing reference!
Is there any better way?
Is there a way of providing the missing library on a machine that doesn't have Outlook installed?
Could I somehow detect in VBA code that the library is or isn't available, and then activate or deactivate a module?
Changing all the DIMs to Objects didn't take too long ... though there was a bit more detective work to track down and change all of the type definitions in parameter lists, and the return value of Functions.
Not too many "SET" statements to add - in fact there might not have been any, as my top level object (the Outlook application) was already so created, and all the other objects as derivatives of that.
Slightly harder was tracking down the Outlook enumerated constants (eg "olMailItem") which popped up in the code from time to time and which had to be replaced by their actual values.
The main thing I had to get straight was that it's not enough to do all of that - I also had to remove the Reference to the Outlook Library, as its mere presence was enough to cause Access to fail on startup on a non-Outlook machine.
That was a shame, as I found a really neat way to tell if there is a broken reference:
Dim ref as Reference
For Each ref in References
If ref.IsBroken Then
If ref.Guid = ...
But this is no use if the program will refuse to run if the reference is included in the program!
Anyway, the solution in the end was just to leave out the Reference altogether. Early on, my code attempts to connect to Outlook and (trapping the error) if it fails then I set a global variable to tell me not to bother trying again.