Link to home
Start Free TrialLog in
Avatar of Declan Basile
Declan BasileFlag for United States of America

asked on

Problem instantiating an .net object from VBA

An Access 2003 program has a reference to a .net dll.  *On one computer only (the other computers don't have this problem)*, vba throws an error when it tries to create an instance of a class defined in the dll.  Vba declares a variable of that type without an error; it's when it tries to create an instance of the class types that it throws an error.  The error message is "Class does not support Automation or does not support expected interface."  I wrote code so show the references, and the reference to the .dll has the correct path and is not broken.  xyz.dll and xyz.tlb are both in the SysWOW64 folder, and when I run "regasm.exe xyz.dll /codebase" I get a successful message.  I even tried to reinstall Access 2003 runtime and I tried unregistering and re-registering xyz.dll but still have the same problem.  How can I fix this problem?


Avatar of Chinmay Patel
Chinmay Patel
Flag of India image

Is it possible that the dll you are referring to has a specific dependency on a .Net version and that computer does not have specific .Net version installed? 
First of all: I'm pretty sure, that Access 2003 RT is no longer supported. Here you should update.

Then: Using COM+ automation requires correctly installed (regasm) components. Depending on the component, their installer and number of updates over a longer period, the registry entries can get wrong. Here uninstalling all versions of that component and doing a clean reinstall should do it. Also check whether your DLL and TLB are of the same version.

And finally as @Chinmay could by right: If your component is as old as the used RT, then the needed .NET framework is not installed per default on actual machines.
Avatar of Declan Basile

ASKER

How can I completely uninstall all versions of xyz.dll?  I've already unregistered it and re-registered it with no success.  Is this the same as completely uninstalling and re-installing it or are there other steps to take?  After ensuring that the dll and tlb were in the syswow64 folder (and checking that they are the same version) I executed "regasm.exe xyz.dll /unregister" and then "regasm.exe xyz.dll /codebase".  I got a successfully registered message but the Access program still can't instantiate the object.  Even though the /codebase option worked on all the other computers, should I try using the /tlb:xyz.tlb option?  Also, is it enough to see that there is a "v4.0.30319" folder to confirm that the computer has the correct version of .net or should I confirm this some other way?  Thank you.
Also, a different .dll is registered and works successfully from the Access program on that computer.  That dll targets framework 4.5.2.  The troublesome .dll targets framework 4.  It's a Windows 10 computer, and when I tried installing .net 4 I got a message that said the operating system already contains this version or a higher version so it wouldn't install it.  Given this message, it sounds to me that frameworks are backwards compatible, so as long as the computer has version 4 or higher it should work.
To uninstall the DLL:
1)  Unregister it
2)  Delete all copies of it.


Also ensure you register the problematic DLL, generating the TLB in the same location as the other computers.  Access must be closed while doing this.
Also we use regsvr32 - not regasm with our DLLs.  Maybe that's your problem?  But we also use the XYZ tlb.  Ensure the DLL is the same as on the other computers?  Would recommend you copy the DLL from one of the working computers to see if that makes a difference.
Good catch, @Kyle.
I tried regsvr32 but got an error about not finding the entry point.  Even though all the other computers worked fine with the tlb that was already created, I deleted the .tlb from syswow64, used regasm with the /tlb option to create a new tlb file, after which a message said that the tlb was both created and registered.  It still didn't fix the problem, so I used regasm again with the /codebase option and the newly created tlb and that fixed the problem.
ASKER CERTIFIED SOLUTION
Avatar of Declan Basile
Declan Basile
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Declan, no issues with you finding your own solution, but can you post what you actually did so anyone else coming across this might benefit from your experiences?