英文:
How to look if system.__comobject is open before I run that object?
问题
我有一个动态对象来获取Access中的system.__comobject:
dynamic app = Marshal.GetActiveObject("Access.Application");
现在我像这样打开一个表单:
app.Run("gbOpenDataEditPart", "ediQuali.170013662.Wawi");
这是有效的,它打开了来自Access的正确表单。现在我想要的是如果已经打开了,就循环执行。我想也许有一个像IsOpen
这样的方法,但它没有打开。有没有另一种方法可以循环检查是否打开?
我尝试了用Powershell脚本来实现,但是窗口也不在那里:
$accessApp = [System.Runtime.InteropServices.Marshal]::GetActiveObject("Access.Application")
$forms = $accessApp.CurrentProject.AllForms
foreach ($form in $forms) {
Write-Host "表单名称: $($form.Name)"
}
我可以看到我想要查看是否已经打开的应用程序,但是当我使用以下代码查看所有表单时:
CurrentProject.AllForms("HPGebote").IsLoaded
或者
CurrentProject.AllForms("ediQuali.170013662.Wawi").IsLoaded
然后找不到具有我正在搜索的名称的表单。
而且,无论我在我的Access中打开哪个表格:
他总是会检测到frmSysAuskunft
,而无论我打开多少个表单,他总是只检测到一个,而且名字总是相同的。
英文:
I have this dynamic Object to get the system.__comobject from Access:
dynamic app = Marshal.GetActiveObject("Access.Application");
And now I open a form like this:
app.Run("gbOpenDataEditPart", "ediQuali.170013662.Wawi");
and that is working. It opens the right form from Access. Now what I want is to loop if this exactly already open. I thought maybe there is a method like if(IsOpen), but it isn't open. Is there another way to loop if this is open?
And I tried it with Powershell script with that but there is the Window not there too:
$accessApp = [System.Runtime.InteropServices.Marshal]::GetActiveObject("Access.Application")
$forms = $accessApp.CurrentProject.AllForms
foreach ($form in $forms) {
Write-Host "Form name: $($form.Name)"
}
I can see my Application which I want to look if it is already open or not but when I look through AllForms with that:
CurrentProject.AllForms("HPGebote").IsLoaded
or
CurrentProject.AllForms("ediQuali.170013662.Wawi").IsLoaded
then there is no form which has the name I am searching for.
And no matter which Formular I will open in my Access:
He will always detect frmSysAuskunft and thats It no matter how many Forms I will have Open he will always just detect one with always the same name
答案1
得分: 0
你好,以下是你提供的代码的翻译:
好的,我只需添加这一行:
使用 Microsoft.VisualBasic;
然后在我的代码中可以这样做:
按钮打开表单,按钮关闭表单,以及按钮测试/检查表单是否打开。
private void button1_Click(object sender, EventArgs e)
{
dynamic app = Interaction.GetObject(Class: "Access.Application");
app.DoCmd.Openform("tblHotelsA");
}
private void button2_Click(object sender, EventArgs e)
{
dynamic app = Interaction.GetObject(Class: "Access.Application");
bool IsOpen = app.CurrentProject.AllForms("tblHotelsA").IsLoaded;
MessageBox.Show($"表单 tblHotelsA 的状态 \n 是否打开:{IsOpen.ToString()}");
}
private void button3_Click(object sender, EventArgs e)
{
dynamic app = Interaction.GetObject(Class: "Access.Application");
app.DoCmd.Close(2,"tblHotelsA");
}
希望对你有所帮助!
英文:
Ok, I just add this:
using Microsoft.VisualBasic;
And now in my code I can do this:
button to open form, button to close the form, and button to test/check if form is open.
private void button1_Click(object sender, EventArgs e)
{
dynamic app = Interaction.GetObject(Class: "Access.Application");
app.DoCmd.Openform("tblHotelsA");
}
private void button2_Click(object sender, EventArgs e)
{
dynamic app = Interaction.GetObject(Class: "Access.Application");
bool IsOpen = app.CurrentProject.AllForms("tblHotelsA").IsLoaded;
MessageBox.Show($"Status of form tblHotelsA \n Open:{IsOpen.ToString()}");
}
private void button3_Click(object sender, EventArgs e)
{
dynamic app = Interaction.GetObject(Class: "Access.Application");
app.DoCmd.Close(2,"tblHotelsA");
}
So, the result is this:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论