Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wait for non modal form to close 1

Status
Not open for further replies.

PeDa

Technical User
Oct 10, 2002
227
NL
My application has a number of non-modal forms that can be opened from the menu. I want one menu option to open them all once in sequence. The forms are not modal because they temporarily open reports in print preview mode, which the user must took at and possibly print. The second form must not open until the first form, and its print preview tab, have closed. Any suggestions welcome.
 
You would have to use the form timer or the timer class to do that. I made a form that I open hidden. I called it "frmSequenceTimer". This form controls the opening of the other forms. Each time a form in the sequence is closed, it removes it from the sequence and opens the next. The timer continually checks that it is still open.

Code:
private FormSequence As New Collection
private currentForm As String  'Name of the open form

Private Sub Form_Open(Cancel As Integer)
  'Add all your forms to the list
  FormSequence.Add "frmOne"
  FormSequence.Add "frmTwo"
  FormSequence.Add "frmThree"
  'Openfirst form
  DoCmd.OpenForm "frmOne"
  currentForm = "frmOne"
End Sub

Private Sub Form_Timer()
  Dim frm As Access.Form
  Dim currentFormOpen As Boolean
  'need to set the timer interval to something other than 0
  'Check to see if the current form is still open.  If not open the next form
  For Each frm In Forms
    If frm.Name = currentForm Then
      currentFormOpen = True
      Exit For
    End If
  Next frm
  If Not currentFormOpen Then OpenNextForm
End Sub

Public Sub OpenNextForm()
  Dim frmName As String
  If FormSequence.Count > 1 Then
    FormSequence.Remove 1
    frmName = FormSequence.Item(1)
    currentForm = frmName
    DoCmd.OpenForm (frmName)
  Else
    DoCmd.Close acForm, Me.Name
  End If
End Sub
 
Thank you MajP; this seems an elegant solution.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top