我有一个sub来实例化一个新表单,使其可见。然而,新形式只持续了很短的时间。这是我的代码:
Private Sub txtProject_ID Click()
Dim frmReq as Form
Set frmReq = New Form_Request
frmReq.Visible = True
End Sub
我尝试在此设置断点,并发现当我将其可见性设置为true时,表单变得可见。然而,一旦Sub结束它就会消失。
编辑: 如何创建弹出窗体的多个实例?
答案 0 :(得分:1)
在Access VBA中使用
DoCmd.OpenForm "Request"
如果你需要打开它隐形你做
DoCmd.OpenForm "Request", WindowMode:=acHidden
' Initialize stuff while invisible
Forms!Request!foo = "bar"
' show form
Forms!Request.Visible = True
要打开多个实例(在问题中有帮助提及)并传递参数,请以下列形式创建公共初始化函数:
Public Sub InitForm(ReqId As Long)
' e.g.
Me.Filter = "Request_ID = " & ReqId
Me.FilterOn = True
'show me
Me.Visible = True
End Sub
并像这样调用它(见https://msdn.microsoft.com/en-us/library/office/ff845819.aspx的底部)
Option Compare Database
Option Explicit
' This variable must be on *module* level!
Dim frmReq as Form
Private Sub txtProject_ID Click()
Set frmReq = New Form_Request
Call frmReq.InitForm(Me!txtProject_ID)
End Sub
答案 1 :(得分:1)
范围的变量/对象仅限于子过程,因此它需要是表单级别。