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!

MDIForms and Child Forms

Status
Not open for further replies.

natashaXXX

Programmer
Sep 13, 2002
13
GB
I have already set up an MDIForm with a child form (with textbox for editing files), and the one and only menu is on the MDIForm. I feel i have gone too far to change the menu to the child form.

problem.
ex. I have two child forms open, one with amendments and one without, and i go to close each form. How can I determine which forms I will need to ask the user whether they wish to save because changes have been made.

Simply having a global boolean change when a txt_change occurs isn't enough as the active form could change to the one which hasn't had any amendments.

Would be grateful for any help.
 
Declare a Public blnChanged Boolean in each Form's general declarations section. Let each form keep track of and update its own blnChanged variable. When you're closing forms, check each form's blnChanged variable independently.

Dim intResponse As Integer
If Form1.blnChanged Then
intResponse = MsgBox("Would you like to save your changes?", vbYesNo, "Save Changes")
If intResponse = vbYes Then Form1.SaveChanges
End If

That example assumes your form has a publicly declared SaveChanges Sub/Function.
 
A very simple way would be to put a public variable in the form code. Then, you can check the value:

Public mp_bDirty As Boolean
If Form1.mp_bDirty Then

Or,
If Not MainMDI.ActiveForm Is Nothing Then
Select Case MainMDI.ActiveForm.Name
Case "Form1", "Form2"
If MainMDI.ActiveForm.mp_bDirty Then

Or, the best is to do something like this:

Use a Private Variable and check in the form Query Unload

Private m_bDirty As Boolean

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

If m_bDirty then
'Call function proceedure to ask user if they want to save or not. The function returns a boolean value: True means the user saved the data, or desired not to save at all; False means the user wants to cancel unloading and return to the form
If SaveProc() Then
'Ok to unload
Else
Cancel = True
End If
End If
End Sub [/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Of course... the Query_Unload event.
That probably is the best way to handle it.
 


The reason why the last of the 3 suggestions that I offered may be better, is beacuse:
with the first one you would need to always list up the forms that need to be checked;
With the second one you would need to either have an error catcher in case the form doesn't have this variable, or make sure that ever form has the variable, even the About form, etc.

The third way encapsulates the check completely and only when the user tries to unload that form, or close the application will that form respond - you should only add a loop in the MDI's Query Unload event to unload all forms in the VB:Forms collection (should have one there anyways, whether this save checker is needed or not) [/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top