Call procedure in access module from .Net?

I'm having problems automating Access 2007 with .Net, either VB or C #. All I want to do is call the subroutine in the Access module from .Net.

Ultimately, I have to get it to work in VB, but I tried to achieve the same results.

Below is the code in my VB test form. This results in an error:

System.Runtime.InteropServices.COMException (0x800A9D9F): HRESULT exception: 0x800A9D9F on Microsoft.Office.Interop.Access.ApplicationClass.Run (String Procedure, Object & Arg1, Object & Arg2, ..., Object &; Arg30)

My test Sub in Access is called "MyTest" and is a module named "Module1". All he does is insert one record into the table. It works great from Access. I tried various permutations of "Module1.MyTest", "MyTest ()", "Call MyTest", etc., no luck.

I found several other examples on the access automation network (and other Office applications), but it seems that it cannot get them to work. If anyone could point me to a working example, I would be grateful.

Code example:

Imports Access = Microsoft.Office.Interop.Access
Imports Microsoft.Office.Core

Public Class FormTest
    Private Sub cmdTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdTest.Click

        Dim aa As New Access.Application()

        Try
            aa.OpenCurrentDatabase("c:\Test.accdb")
            aa.Run("MyTest")
        Catch ex As Exception
            MsgBox(ex.ToString())
        Finally
            If aa IsNot Nothing Then
                aa.Quit(Access.AcQuitOption.acQuitSaveNone)
            End If
            Me.Close()
        End Try

    End Sub
End Class
+3
source share
3 answers

It was safety. In Access, I had to disable security checking. As soon as I did this, it worked fine.

+2
source

InnerException ( ).

, VB6 - VB6 , .
- , VB.net

EDIT: MyTest ?

0

, ODBC OLEDB .mdb, , , SQL?

, , , Access.

0

Source: https://habr.com/ru/post/1707912/


All Articles