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

Intercept Call to Close Data Entry Form 1

Status
Not open for further replies.

CDavis

Programmer
May 5, 2000
155
US
I'm starting a new project in VFP 9

In past projects I've not included a ControlBox on forms opting instead for an "Exit" button on the form. However for this project, I'd like to include the Control Box.

I have been unable to find documentation on the order of events that occur after the user selects 'Close' from the control box (or a click on the 'X')

Based on tests, I know that the Destroy Event occurs prior to Unload. But, are there other events and what is the preferred means/location for intercepting the call to close the form when data has not been saved? Is there a way to cancel the call programatically? Would I need to place code in the valid event of every control on the form?

For now, in the Destroy Event of the form, I've placed the following code but I'm interested in knowing what others are doing and what is considered 'Best Practice'

Code:
IF THISFORM.RELEASETYPE=1  && User Clicked the "X" to Close the Form

	cMessageTitle = ' Caution '
	cMessageText = "Information Has Not Been Saved" ;
		+ CHR(13) +CHR(13) + "Do You Want to Save Now?" ;
		+ CHR(13) + CHR(13) ;

	nDialogType = 4 + 16 + 0
		*  4 = Yes & No buttons
		*  16 = Stop Sign icon
		*  0 = First button is default
	nAnswer = MESSAGEBOX(cMessageText, nDialogType, cMessageTitle)

	DO CASE
	CASE nAnswer = 7  && No Button Pressed
		=TABLEREVERT(.T.,"Eval")
	OTHERWISE
		*** Yes Button Pressed -- Process Information & Save
		*
		*
	ENDCASE

ENDIF

Thanks in advance for your help.

CDavis
 
Hi CDavis,

I think the event you are looking for is QueryUnload. It is fired when the user clicks the Close button, before the Destroy. It's often used to ask the user's confirmation, or to check for unsaved edits.

If you want to prevent the form from being closed, execute NODEFAULT in the QueryUnload.

Note that QueryUnload is NOT called when you issue THISFORM.Release.

Does that help at all?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Thanks Mike,

That's exactly what I was looking for.

I appreciate the quick response.

CDavis
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top