Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2010
    Posts
    88

    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?

    Other ideas?

    TIA
    CeejayDBF

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You can:
    1. Use late biding to instanciate the objects from the Outlook library. You declare them as objects and use CreateObject to initialize them:
    Code:
    Dim MyObject As Object
    Set Myobject = CreateObject("ObjectType")
    2. Find a method to know whether the Outlook library is installed on a machine (there are several) and use the technique described in 1. only if it is.

    That way all modules can be compiled without any error due to a missing library and no attempt to create an object of a type referring to a missing library will never be made.
    Have a nice day!

  3. #3
    Join Date
    Mar 2010
    Posts
    88
    Thanks, that looks like it is a good direction to go in, I will give it a go and report back....

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome!
    Have a nice day!

  5. #5
    Join Date
    Mar 2010
    Posts
    88
    Well, that took a while....

    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:
    Code:
    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.

    Sorted.

    Thanks.

  6. #6
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome!
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •