Make Sure Data is Safe Before Unloading

To decide when it is safe to exit your program, use a DataUnsafe function. Set the DataModified variable to False when you load or save data, or when you start a new file. Set DataModified to “OK” to remove the current data:

 Dim DataModified As BooleanPrivate Function DataUnsafe() As Boolean	If DataModified Then		Select Case MsgBox _			("Save changes to the data?", vbYesNoCancel)			Case vbYes				' Save the data. SaveData should 				' set DataModifed False if successful.				SaveData				DataUnsafe = DataModified			Case vbNo				' OK to clear data.				DataUnsafe = False			Case vbCancel				' Cancel operation and keep data.				DataUnsafe = True		End Select	Else		' The data is not modified.		DataUnsafe = False	End IfEnd FunctionPrivate Sub Form_Unload(Cancel As Integer)	Cancel = DataUnsafe()End Sub
Share the Post:
Share on facebook
Share on twitter
Share on linkedin


Recent Articles: