2016-04-12 9 views
0

Ich versuche, ein Makro von MS Access 2010 von vb.net 2010 ..Wie ms Zugangsmakro von vb.net ausführen?

Der Code I ist

Dim oAccess As Access.ApplicationClass 

     'Start Access and open the database. 
     oAccess = CreateObject("Access.Application") 
     oAccess.Visible = True 
     oAccess.OpenCurrentDatabase("C:\Users\Yuganshu\Desktop\New folder (4)\WindowsApplication1\db.mdb", False) 

     'Run the macros. 
     oAccess.Run("Macro1") 
     'oAccess.Run("DoKbTestWithParameter", "Hello from VB .NET Client") 

     'Clean-up: Quit Access without saving changes to the database. 
     oAccess.DoCmd().Quit(Access.AcQuitOption.acQuitSaveNone) 
     System.Runtime.InteropServices.Marshal.ReleaseComObject(oAccess) 
     oAccess = Nothing 

folgende Fehler Dies gibt mir verwendet auszuführen:

Unable to cast COM object of type 'Microsoft.Office.Interop.Access.ApplicationClass' to class type 'WindowsApplication1.Access.ApplicationClass'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.

Ich weiß nicht, was ich machen soll.

Antwort

1

Sie müssen die richtige COM-Referenz hinzufügen. Klicken Sie auf die Projektmenüleiste und dann -> Referenz hinzufügen. Suchen Sie unter Typbibliotheken nach Microsoft Access 14.0 oder welcher Version Ihr Computer gerade ausgeführt wird. Fügen Sie dann die folgenden Anweisungen hinzu.

Imports Microsoft.Office.Interop 

Dim Access_Object As New Access.Application 
Access_Object = CreateObject("Access.Application") 
Access_Object.Application.Visible = True 
Verwandte Themen