vba 使用模态或弹出窗口打开表单
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13174473/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Open Form with Modal or Popup Window
提问by user1531401
Struggling a bit with this, I have a datasheet form which lists the ID and other info for each record. So far I have found some VBA code which will open each ID as a hyperlink and pass that into another form.
对此有点挣扎,我有一个数据表表单,其中列出了每条记录的 ID 和其他信息。到目前为止,我已经找到了一些 VBA 代码,它会将每个 ID 作为超链接打开并将其传递到另一个表单中。
The problem I have is I wanted the form to open in a popup or modal window, my code so far is:
我的问题是我希望表单在弹出窗口或模式窗口中打开,到目前为止我的代码是:
Private Sub ID_Click()
Dim varWhereClause As String
varWhereClause = "ID = " & Me!ID
DoCmd.OpenForm "Copy Of test", , , varWhereClause
End Sub
回答by Daniel
DoCmd.OpenForm "Copy Of test", , , varWhereClause, ,acDialog
Though this will be pop-up and modal.
虽然这将是弹出窗口和模式。
回答by user3305711
A small disadvantage of acDialog
and .PopUp
is that the form opens as window outside the access main window. That's why I prefer to use just .Modal
if possible.
的一个小缺点acDialog
并且.PopUp
在于,窗体打开作为访问主窗口之外的窗口。这就是为什么我更喜欢.Modal
在可能的情况下使用。
If you just want to block other open forms you can do a Me.Modal = True
even temporarily in the open event of your form.
如果您只想阻止其他打开的表单,您Me.Modal = True
甚至可以在表单的打开事件中临时执行一个操作。
The disadvantage of .Modal
is that it will not wait. DoCmd.OpenForm , , , , , acDialog
doesn't return until the form is closed. Such a synchronous call can be very useful sometimes.
缺点.Modal
是不会等待。DoCmd.OpenForm , , , , , acDialog
在表单关闭之前不会返回。这种同步调用有时非常有用。
To do an acDialog/PopUp
like call that stays insidethe access main window you can use a little trick inside your form:
要在访问主窗口内执行acDialog/PopUp
类似调用,您可以在表单中使用一个小技巧:
Private bFormOpen As Boolean
Public Sub ShowModal()
SetFocus ' Make the form visible
On Error GoTo ForcedClose
bFormOpen = True
Do While bFormOpen ' Wait until the form is closed
Sleep 50
DoEvents
Loop
ForcedClose:
Exit Sub
End Sub
Private Sub Form_Unload(Cancel As Integer)
bFormOpen = False
End Sub
You can than instantiate your form like this:
你可以像这样实例化你的表单:
Dim f As New Form_Name
f.Modal = True
Call f.ShowModal
Set f = Nothing