Using .NET / C# API via MS Access/VBA

I have a Microsoft Access application and want to give the ability for users to dial telephone numbers and record calls (via an API).  I have looked at several platforms that would allow me to do this.  However, most of the solutions that I have seen only support the usual protocols .Net, Java, PHP - not VBA.  I have created a few small c# applications - but it isn't an environment that I would say I was all that proficient in.  That said, I can learn.

Although it feels a little clunky to me, I was wondering whether I should create a small c# application (with the suppliers API), and use it as middleware?  Ideally, I'd control everything through VBA and then just make the calls as necessary.  For example, Dial number, pull in connection time, add key-pad etc.  However, before embarking on this project - I could just do with some guidance as to best-practices (or any other suggestions you may have).

Thanks as always.
Andy BrownDeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
It's certainly doable. I'm more comfortable with the command line method instead of requiring a reference to your .NET app. That way, the only thing your VBA would need to know is the full path to the .NET app, and you could call it with the Shell or ShellExecute syntax.
Andy BrownDeveloperAuthor Commented:
Thanks Scott - but I also need to get information back from the API (connection time, recording ID etc.), which makes it a little harder.
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Write that information back to the database from the .NET executable.

Also, I'm not saying you can't do this with a .NET dll file. You can, and it's done quite a bit. I just found that working with a self-created DLL file can sometimes be troublesome with versioning and references and such. For simple processes like this, I found the executable with command line switches to be easier to deal with.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

I don't have any code examples but my understanding is that you would need to write a COM wrapper function that VBA can call and that will communicate with .net
Kyle AbrahamsSenior .Net DeveloperCommented:
It can be done but it's a little bit of hoops to go thru.

The easiest way to do it is:

    public class myClass
   public string MyString {get; set;}
   // full implementation

Open in new window

Note that you can't use static classes in com.
Once the DLL is built you then have make the assembly com visible.
When deploying it you use regasm to with the /codebase switch to generate the TLB.
You then reference the TLB in access
and from there you can use the TLB like any other referenced module in access.
Andy BrownDeveloperAuthor Commented:
Thank you everyone - the most straightforward solution does seem to be to write a small c# app, called from the command line and then feed the return information back via the app.  The only tricky part that I see is getting the form to display real-time changes.  For example, if the phone line is engaged, the user needs a message (through the MS Access form), to indicate that the phone line is engaged.  I'm sure lots of other things will come up - but it's worth looking at.

Thanks again
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.