Open Form with Modal or Popup Window

前端 未结 2 1451
无人及你
无人及你 2021-01-06 21:20

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 hyperli

相关标签:
2条回答
  • 2021-01-06 21:35

    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.

    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.

    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.

    To do an acDialog/PopUp like call that stays inside the access main window you can use a little trick inside your form:

    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
    
    0 讨论(0)
  • 2021-01-06 21:45
    DoCmd.OpenForm "Copy Of test", , , varWhereClause, ,acDialog
    

    Though this will be pop-up and modal.

    0 讨论(0)
提交回复
热议问题