如何检查是否访问2010窗体的实例仍然是开放的? [英] How can I check if an instance of a Access 2010 form is still open?

查看:385
本文介绍了如何检查是否访问2010窗体的实例仍然是开放的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有必要建立一个搜索表单的多个副本(在使用2010 )返回一个值给调用(这也是创建窗体实例的形式)。

I have a need to create multiple copies of a search form (in Access 2010) that returns a value to the calling (which is also the form that created the instance of the form).

如前所述这些形式可以与将具有在同一时间,例如运行多个拷贝的用户可能希望将公司添加的东西,这样他们

As mentioned these forms could and will have multiple copies running at the same time for example a user could want to add a company to something so they:

  • 点击选择公司,打开了公司搜索画面的一个实例
  • 在这时,他们发现该公司有一个母公司尚未添加尚未开公司的编辑器(在离开原公司搜索/选择屏幕打开时)。
  • 在他们然后点击选择母公司按钮,在打开的搜索和选择屏幕的另一个实例
  • 他们发现,母公司
  • 选择它而关闭第二搜索屏幕和母公司被添加到第一公司
  • 然后,用户选择使用原始搜索屏幕这再次关闭所述原搜索屏幕,并返回选定的公司以什么都形成他们最初初始化第一搜索...
  • 修饰的公司
  • Click "select company" and open an instance of the company search screen
  • Then open the company editor (leaving the original company search/selection screen open) as they notice the company has a parent company that hasn't been added yet.
  • They then click the "Select Parent Company" button that opens ANOTHER instance of the search and select screen
  • They find the parent company
  • Select it which closes the second search screen and the parent company is added to the first company.
  • The user then selects the modified company using the original search screen which again closes the original search screen and returns the selected company to what ever form they originally initialised the first search...

这都允许用户更新和正确的数据,当他们发现错误,减少了他们遗忘的可能性,使得它更快!

This all allows the users to update and correct data as and when they find error which reduces the likelihood of them forgetting and makes it much quicker!

这其中大部分是好的,但现在我已经有很多的问题,有一种形式的不能够打开一个acDialog,从而阻止调用code运行,直到搜索做实例(见<一HREF =htt​​p://stackoverflow.com/questions/8338895>这个问题获得更多信息),我已经用是用无限循环来模拟调用code中的暂停解并检查是否搜索屏幕瞬间仍是可见的。然后,当用户选择的东西在搜索屏幕即时它把在一个隐藏字段的值在搜索屏幕和隐藏它的自我(未关闭)。调用函数然后看见它的隐藏抓起从隐藏字段中的值和卸载的瞬间。

MOST of this is fine now but I have had a lot of problems with instances of a form not being able to open as a "acDialog" thus stopping the calling code running until the search was done (see this question for more info) and the solution I have gone with is to simulate the pausing of the calling code by using a endless loop and checking if the search screen instant is still visible. Then when the user selects something on the search screen instant it puts the value in a hidden field in the search screen and hides it's self (not closed). The calling function then sees it's hidden grabs the value from the hidden field and unloads the instant.

我可以检查的形式使用FormInstant.Visable 隐藏的,但如果用户关闭表单这将导致一个错误,并且code我通常会用它来检查是否存在形式要求一个窗体名称和,因为它是一种形式的所有形式的具有相同名称的瞬间!我有一个参考的形式,因为它是存储在本地表对象......在code,我通常会使用是:

I can check if the form is hidden using FormInstant.Visable but if the user closes the form this causes an error and the code I would normally use to check if the form exists requires a form name and as it's an instant of a form all the forms have the same name! I do have a reference to the form as it is stored in a local "form" object... The code I would normally use is:

CurrentProject.AllForms("FormName").IsLoaded

所以,我怎么能检查的一种形式的即时加载还是?

So how can I check for a instant of a form being loaded still?

推荐答案

LOL我才意识到,而重新阅读我的味精,我可能可以捕获错误摸出如果表单是打开还是不行!

LOL I just realised while re-reading my msg that I can likely trap the error to work out if the form is open or not!

我也很快写了这个,它似乎做工精细:

I have quickly written this and it seems to work fine:

Public Function IsFormLoaded(ByRef FormToTest As Form, _
                            Optional ByRef bIsVisable As Boolean = False) As Boolean
    Dim lErrorNum As Long
    bIsVisable = False
    On Error Resume Next
        bIsVisable = NewFormClone.Visible
        lErrorNum = Err.Number
    On Error GoTo 0

    If (lErrorNum = 0) Then
        IsFormLoaded = True
    Else
        IsFormLoaded = False
    End If
End Function

猜猜它并没有真正母校谁,只要是回答未来的家伙/加仑可以用它回答了这个问题的:!)

我将离开这个开了一下,如果没有人找到一个更好的答案,我将标志着这个,因为它...

I will leave this open for a bit and if nobody finds a better answer I will mark this as it...

这篇关于如何检查是否访问2010窗体的实例仍然是开放的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆