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

Form_Close problem 1

Status
Not open for further replies.

sabavno

Programmer
Jul 25, 2002
381
CA
Hi

I have an new entry form. My 'save' and 'exit' buttons work to add a new a record and exit the form

But when user click on 'X' close button of the form (which hits Form_Close event where I didn't code anything, the record would still be added, why is that? What should I code on Form_Close event to prevent the record from being added to the database

Thanks
 
Hi!

Create a form level boolean variable called bolSave. In the form load procedure set bolSave to false. In the form beforeupdate procedure use:

If bolSave = False Then
Me.Undo
Else
The rest of your code here
End If

In the click event for the Save button (and the Exit button if that is appropriate) set bolSave to True. Of course you may well need to adjust this structure to better suit your business requirements, but this should give you a general starting point.

hth
Jeff Bridgham
bridgham@purdue.edu
 
If the form is based on a updateable record source, each record will be saved when you close the form. No matter how you close it.

Actually, I believe the field is saved as soon as you leave the field.

One way around it is having a yes/no field "saverec".
The default value is "no".

Your saved button should just update the field to "yes",
then close the form.

You should then run a query on form_close event, that deletes all records that have "saverec" set to "no".

What do you think?

David I'm Your Huckleberry!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top