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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I want to open forms both as MDI Children and Modally

Status
Not open for further replies.

vcurry

Programmer
May 20, 2003
7
GB
I've got a situation where I want to open the same form both as an MDI child, and from a Modal Form. This is a bit of a problem as a MDI Child Form can't be Modal. The work around I have at the moment is to have two forms, one MDI Child and one not, and have their code in a module. As a solution it works, but I was wandering if anyone had any neater ideas.

Thanks.
 


Hi:

One work-around that we have used on occasion is a "Lock_Records" routine that we created. In each form, we put the following code:
Code:
Public Sub LockRecord()
    Static blnInProgress As Boolean
    
    If blnInProgress Then Exit Sub
    If m_intEditMode <> adEditNone Then
        Me.Enabled = False
    Else
        If Not blnInProgress Then
            blnInProgress = True
            myMom.LockRecord
            blnInProgress = False
        End If
    End If
End Sub

Public Sub UnlockRecord()
    Me.Enabled = True
End Sub

myMom in the above code is the MDI form, assigned by a call to a sub in each form's code. When a form needs to lock out other forms (in effect be a vbModal form), it calls its LockRecord, which calls the MDI's LockRecord, which then calls each form's LockRecord. After the form is done, it calls the MDI's UnlockRecord, which then calls each form's UnlockRecord.

The MDI LockRecord sub is typically like (the forms are stored in collections):
Code:
Friend Sub LockRecord()
    Dim I As Integer
    '
    For I = 1 To colStudents.Count
        colStudents.Item(I).LockRecord
    Next I
    '
    For I = 1 To colTeachers.Count
        colTeachers.Item(I).LockRecord
    Next I
    '
    For I = 1 To colClasses.Count
        colClasses.Item(I).LockRecord
    Next I
    '
End Sub

It is a kluge but it works.

I am open to other suggestions.

Cassie
 
Thanks Cassie.

However, I don't think this solves my problem. From reading your solution I think this gives a modal form experience for the user in that they can't access any of the other forms until the Unlock method of the forms is called. However, my problem is that if I am in a modal form already, how would I call a form that has it's MDI child Property set to true?

Having typed my reply, I now see how your method could be useful in our situation. We would implement these methods in all the forms, and then we could simulate the Modal form functionality by calling the lock method method.

Thanks,

Vincent
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top