save after YES NO Question

R

Rivers

im wondering if this is possible but i have an 'ok' button at the bottom of
my form
it automatically saves the records when i close using docmd.close

what im looking for i a way for a message box to pop up and ask if they want
to save this record if not then for it to automaticly delete therecord then
close

please help

thanks n advance

Rivers
 
D

Dennis

The problem is that Access does a SAVE under several different conditions:

- When you close the form

- When you navigate to another record

- When you enter a subform bound to a different table

It's fairly simple to do what you asked in your question, but that doesn't
address the other issues I just outlined. Do you want to cover those as well,
or just a CLOSE?

Because for CLOSE, just have (in the EVENT for the CLOSE buttion:

if me.dirty then
x = msgbox ("Do you want to write this record?", vbyesno)

if x = vbYes then
me.dirty = false
else
me.undo
end if
end if
 
R

Rivers

i tried linking this to my button but it des nothing any ideas

if me.dirty then
x = msgbox ("Do you want to write this record?", vbyesno)

if x = vbYes then
me.dirty = false
else
me.undo
end if
end if
 
D

Dennis

Well, you have to have a BOUND form, and you have to have made some change to
it (thus making the form "dirty") before the code inside the IF will execute.
 
J

John W. Vinson

what im looking for i a way for a message box to pop up and ask if they want
to save this record if not then for it to automaticly delete therecord then
close

You may want to reconsider.

In practice, users will edit a record because they want to edit the record. If
they get asked every time "Do you want to edit this record?" their response is
likely to be an annoyed "yes, dammit, that's why I edited it"; after a while
they'll just click Yes unthinkingly every time, and you'll be back where you
were.

This *can* be done... but as a rule, it's counterproductive!

If you want to prevent unintentional editing, have your default form read-only
(by basing it on a non-updateable query for example), and have a command
button to open an edit form so the user must make an intentional choice to do
so.

John W. Vinson [MVP]
 
Top