Reputation: 79
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.
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
Upvotes: 5
Views: 65365
Reputation: 451
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
Upvotes: 4
Reputation: 13122
DoCmd.OpenForm "Copy Of test", , , varWhereClause, ,acDialog
Though this will be pop-up and modal.
Upvotes: 11