[英]Open multiple forms issue in Access
I got query to make some modification that enable user to open multiple instances of the form when they do search data. 我查询到进行一些修改,使用户在搜索数据时可以打开表单的多个实例。 I got manage to create a new module following Allen Browne guide and now I can open multiple instances of the spreadsheet which is good step forward but I cannot find solution how I can open that specific form.
我设法按照Allen Browne指南创建了一个新模块,现在我可以打开电子表格的多个实例,这是向前迈进的好一步,但我找不到如何打开该特定表格的解决方案。
In module I have got following code: 在模块中,我有以下代码:
Public clnClient As New Collection 'Instances of frmClient.
Function OpenAClient()
'Purpose: Open an independent instance of form frmClient.
Dim frm As Form
'Open a new instance, show it, and set a caption.
Set frm = New Form_SurgeriesForm
frm.Visible = True
frm.Caption = frm.Hwnd & ", opened " & Now()
'Append it to our collection.
clnClient.Add Item:=frm, Key:=CStr(frm.Hwnd)
Set frm = Nothing
End Function
And under my button I replaced bit: 在我的按钮下面,我替换了一下:
DoCmd.OpenForm "SurgeriesForm", acNormal
Forms!SurgeriesForm.Requery
.. and usef following code: ..和usef以下代码:
ModuleInstances.OpenAClient
I recon I need to add / change somehow the code below to be able to open multiple instances but do not have idea how to do it. 我确认我需要以某种方式添加/更改下面的代码,以便能够打开多个实例,但不知道如何执行。
DoCmd.OpenForm "SurgeriesForm", acNormal
Forms!SurgeriesForm.Requery
I appreciate for any help with this as i got stuck and do not know how I can achieve this. 感谢您为我提供的任何帮助,我不知道该如何实现。
I think this is what you want?... 我想这就是你想要的?
With the button on your SurgeriesForm
add this code to the On Click
event to open a new instance of the form: 使用
SurgeriesForm
上的按钮,将此代码添加到On Click
事件中,以打开表单的新实例:
Private Sub Command8_Click()
OpenAClient
End Sub
This will create a new instance of the form each time you click the button. 每次您单击按钮时,都会创建一个新的表单实例。
Next, add a blank combo-box to the form and change it's Row Source Type
to Value List
. 接下来,在表单中添加一个空白组合框,并将其“
Row Source Type
更改为“ Value List
。
Add this code to the form: 将此代码添加到表单中:
Private Sub Combo9_GotFocus()
Dim frm As Variant
Combo9.RowSource = ""
For Each frm In clnClient
Combo9.AddItem frm.Caption
Next frm
End Sub
Now, when you click the drop-down it will list each form that you have created an instance of. 现在,当您单击下拉列表时,它将列出您创建实例的每个表单。
Finally, add this code to the form: 最后,将此代码添加到表单中:
Private Sub Combo9_AfterUpdate()
clnClient(Combo9.Value).SetFocus
End Sub
Now, selecting a form name from the combo-box will move the focus to that form. 现在,从组合框中选择一个表单名称会将焦点移至该表单。
NB: You'll need to update the name of the controls to match yours. 注意:您需要更新控件的名称以匹配您的控件。
NB2: Remember to open the first form using OpenAClient
or it won't get listed in the combobox (as it's not in the collection). NB2:请记住使用
OpenAClient
打开第一个表单,否则它不会在组合框中列出(因为它不在集合中)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.