2012-01-13 18 views
7

Ok, quindi ho un assieme, scritto in C#, utilizzando Visual Studio 2010.Utilizzando una DLL .Net di Microsoft Access VBA

questo sistema contiene una classe, che contiene un metodo che restituisce la parola Risultato, il codice è qui sotto:

using System.Runtime.InteropServices; 

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

la sezione di uscita nella scheda Costruisci sulla finestra delle proprietà assomiglia così:

Visual Studio Output Window

Quando ho CLIC k su Build, ottengo un file DLL e un file TLB. Posso aggiungere questo file TLB a Microsoft Access semplicemente sfogliandolo.

VBA Reference Window

Ora, in Access Ho un bottone e un'etichetta. Voglio rendere la proprietà Caption della mia etichetta uguale al risultato di testMethod. Sto pensando che ho bisogno di fare qualcosa di simile al di sotto, ma non sono sicuro, tutto l'aiuto sarebbe molto apprezzato:

Private Sub btnMain_Click() 

    Dim tm As TestDLL 
    Dim foo As String 

    foo = tm.testMethod 

    lblBarr.Caption = foo 

End Sub 

Grazie

risposta

8

Forse la prossima funzionerà:

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 
+0

Ha lavorato Perfettamente! – JMK

Problemi correlati