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?

.NET ProgrammingVBA

Avatar of undefined
Last Comment
Kyle Abrahams, PMP
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? 
Avatar of ste5an
Flag of Germany image

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


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.
Avatar of Declan Basile


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.
Avatar of ste5an
Flag of Germany image

Good catch, @Kyle.
Avatar of Declan Basile


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.
Avatar of Declan Basile
Declan Basile
Flag of United States of America image

Blurred text
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
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?
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews


IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo