Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a .Net DLL in Microsoft Access VBA

Tags:

c#

vba

dll

vb6

typelib

Ok so I have an assembly, written in C#, using Visual Studio 2010.

This Assembly contains one class, which contains one method which returns the word Result, the code is below:

using System.Runtime.InteropServices;

namespace TestDLL
{
    public class Class1
    {
        [ComVisible(true)]
        public string TestMethod()
        {
            return "Result";
        }
    }
}

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

Visual Studio Output Window

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

VBA Reference Window

Now, in Access I have a button and a label. I want to make the Caption property of my label equal to the result of testMethod. I'm thinking I need to do something similar to 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

like image 292
JMK Avatar asked Jan 13 '12 10:01

JMK


1 Answers

Maybe next 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
like image 169
Arvo Avatar answered Sep 17 '22 13:09

Arvo