Using a .Net DLL in Microsoft Access VBA
Asked Answered
U

1

8

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

Unintelligent answered 13/1, 2012 at 10:22 Comment(0)
P
10

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
Payne answered 13/1, 2012 at 11:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.