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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 14:21:41  来源:igfitidea点击:

Open Form with Modal or Popup Window

vbams-access

提问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 acDialogand .PopUpis that the form opens as window outside the access main window. That's why I prefer to use just .Modalif possible.

的一个小缺点acDialog并且.PopUp在于,窗体打开作为访问主窗口之外的窗口。这就是为什么我更喜欢.Modal在可能的情况下使用。

If you just want to block other open forms you can do a Me.Modal = Trueeven temporarily in the open event of your form.

如果您只想阻止其他打开的表单,您Me.Modal = True甚至可以在表单的打开事件中临时执行一个操作。

The disadvantage of .Modalis that it will not wait. DoCmd.OpenForm , , , , , acDialogdoesn't return until the form is closed. Such a synchronous call can be very useful sometimes.

缺点.Modal是不会等待。DoCmd.OpenForm , , , , , acDialog在表单关闭之前不会返回。这种同步调用有时非常有用。

To do an acDialog/PopUplike 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