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?
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.
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.
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.