如何使用C#代码访问运行在Access上的OfficeLine中的程序?

huangapple go评论67阅读模式
英文:

How can I acces my Programms on my OfficeLine which is running on Access with C# code?

问题

I understand your request, and here's the translated text without the code:

基本上,我正在使用一个运行在Access上的OfficeLine,我的程序列表如下:

OfficeLine程序列表

现在,我想从C#中打开其中一个。

我尝试使用Interop.Access来实现这一点,因为我的C#程序是一个类库程序。

然后,我尝试从Access中获取所有的表单,因为在我的任务管理器中,我的OfficeLine看起来像这样:

任务管理器界面

我使用以下代码来获取表单:

foreach (Form form in accessApp.Forms)
{
    try
    {
        // 检查表单是否已打开
        if (!accessApp.Forms[form.Name].CurrentView.Equals(AcFormView.acDesign))
        {
            if (form.Name == "frmSysControlCenter")
            {
                foreach (Microsoft.Office.Interop.Access.Control control in form.Controls)
                {
                    // 在此处理控件
                }
            }
        }
        else
        {
            // 表单处于设计模式
        }
    }
    catch
    {
        // 如果出现错误,表单未打开
    }
}

frmSysControlCenter 应该是表单,但现在我不知道如何从我的OfficeLine中访问表单,我尝试查看控件,但没有成功。

有没有人有想法如何从我的第一个截图中打开一个表单,比如 Stammdaten -> Artikel

英文:

So bassicly im using an OfficeLine which is running on Access and my programms are list like that:

List of Officline programms

and now I want one of them open from C#.

I tried to use Interop.Access for that because my C# programm is an Class Library program.

And then to get all Forms from Access because in my Task manager my Officline is looking like that:

Task Manager look

and I get the Form with that Code:

foreach (Form form in accessApp.Forms)
                {
                    try
                    {
                        // Überprüfen, ob Formular geöffnet ist
                        if (!accessApp.Forms[form.Name].CurrentView.Equals(AcFormView.acDesign))
                        {
                            //MessageBox.Show("Das ist der if Block:  " + form.Name);

                            if (form.Name == "frmSysControlCenter")
                            {
                                foreach (Microsoft.Office.Interop.Access.Control control in form.Controls)
                                {
                                    
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("Das ist der else Block:  " + form.Name);
                        }
                    }
                    catch
                    {
                        // Falls ein Fehler auftritt, das Formular ist nicht geöffnet
                    }
                }

and frmSysControlCenter should be the Form but now I dont know how to access the formulars from my OfficeLine I thought on something like looking through Controls but that didnt work.

So anyone an Idea how to open an Formular like Stammdaten -> Artikel for example from my first screenshot?

答案1

得分: 0

我自己找到了一种方法,只需使用以下代码:

dynamic app = Marshal.GetActiveObject("Access.Application");
英文:

I found an way by myself and it was just to use this:

        dynamic app = Marshal.GetActiveObject("Access.Application");

huangapple
  • 本文由 发表于 2023年4月17日 15:37:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/76032708.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定