devxlogo

Make Sure Data is Safe Before Unloading

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
See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist