Using DLL.Net in Microsoft Access VBA

So, I have a build written in C # using Visual Studio 2010.

This assembly contains one class that contains one method that returns the word Result, the code below:

using System.Runtime.InteropServices; namespace TestDLL { public class Class1 { [ComVisible(true)] public string TestMethod() { return "Result"; } } } 

The output section on the Build tab in the properties window looks like this:

Visual studio output window

When I click Build, I get a DLL file and a TLB file. I can add this TLB file to Microsoft Access simply by viewing it.

VBA Reference Window

Now in Access I have a button and a shortcut. I want to make the Caption property of my shortcut equal to the result of testMethod. I think I need to do something similar below, but I'm not sure any help would be much appreciated:

 Private Sub btnMain_Click() Dim tm As TestDLL Dim foo As String foo = tm.testMethod lblBarr.Caption = foo End Sub 

Thankyou

+7
source share
1 answer

Perhaps the following will work:

 Private Sub btnMain_Click() Dim tm As TestDLL.Class1 Dim foo As String Set tm = New TestDLL.Class1 foo = tm.testMethod lblBarr.Caption = foo End Sub 
+8
source

All Articles