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

Unload form problem... 1

Status
Not open for further replies.

keeyean

MIS
Sep 29, 2001
32
US
i have 6 forms and a mdiform... below are the code i want to close the forms...

'Close in File menu
Public Sub mnuClose_Click()
Unload Form1
End Sub

Public Sub UnloadAllForm()
Unload Form1
Unload Form2
Unload Form3
Unload Form4
Unload Form5
Unload Form6
End Sub

'Sub in Form1
Public Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Dim Style As VbMsgBoxStyle
Dim Response As VbMsgBoxResult

If FileHasChanged = True Then
Style = vbYesNoCancel + vbQuestion
Response = MsgBox("Do you want to save this file1?", Style)

If Response = vbYes Then
Cancel = True
MDIForm1.mnuSaveAs_Click
ElseIf Response = vbNo Then
UnloadAllForm
FileHasChanged = False
ElseIf Response = vbCancel Then
Cancel = True
End If
Else
UnloadAllForm
End If

End Sub

'Sub in other 5 forms
Public Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Unload Form1
End Sub

am i missing any??
coz .. when i close the form(not Form1)...by clicking the cross at the window corner...
1.) a msgbox will pop up.. but when i press cancel.. the form will invisible
2.) if select yes... once i press cancel from the save dialog.... the form will invisible too...

it work fine when i close the form from the FileMenu, or by clicking the cross at form1...

plz...:(
 
That is because you only Cancelled the Unload of Form1. That does not cancel the unload of the original form. You did not inform the original Query_Unload that it should Cancel.
Code:
' Form Declarations
Private fblnUnloadCancelled as boolean
Public Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
..............
fblnUnloadCancelled = Cancel
End Sub
Public Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Unload Form1
Cancel = fblnUnloadCancelled
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top