Article ID: 150206
Article Last Modified on 6/28/2004
Public Sub ShowModalForm(frmTarget As Form)
Dim c As Collection
Set c = New Collection
'Disable all the forms
For Each ofrm In Forms
If ofrm.Enabled = True Then
c.Add ofrm
ofrm.Enabled = False
End If
Next ofrm
'Now show the target form non-modal
frmTarget.Show
'If the frmTarget was disabled by the loop above
'(because it was invisible) make sure it is now enabled
frmTarget.Enabled = True
'Sit in a loop until the target form is dismissed
Do While frmTarget.Visible = True
DoEvents
Loop
'FIX: Unload the Form
UnLoad frmTarget
'We have left the loop, so the dialog has been closed
'Now Enable the forms that were disabled, and exit the procedure
For Each ofrm In c
ofrm.Enabled = True
Next ofrm
End Sub
Because a non-modal form cannot be shown from a modal form, the routine
above must also be used to show the form prior to the modal form containing
the DBGrid control.
Private Sub Command1_Click()
Form2.Show vbModal
End Sub
Private Sub Command1_Click()
Form3.Show vbModal
End Sub
'FIX: Flag to avoid unloading the form when the user closes it
Private mblnIgnoreUnload as boolean
'FIX: Additional Code for Form_Load of Form2
Private Sub Form_Load
mblnIgnoreUnload = True
End Sub
'FIX: Additional Code for Form_QueryUnLoad of Form2
Private Sub Form_QueryUnLoad
If mblnIgnoreUnload Then
Me.Hide ' Make Form2 Invisible
Cancel = True ' Do not unload Form2
mblnIgnoreUnload = False ' Next time we come here unload Form2
End If
End Sub
Private Sub Command1_Click()
ShowModalForm Form2
End Sub
and change the Command1_Click event in Form2 to:
Private Sub Command1_Click()
ShowModalForm Form3
End Sub
Now the forms correctly display and act like Modal forms, but the program
does not hang when Form3 is dismissed.
Additional query words: 4.00 vb4win vb4all buglist4.00
Keywords: kbbug KB150206