Dirty Method


S

Secret Squirrel

I'm trying to use a popup message when a users clicks the close button on my
form to ask them if they want to exti without saving. If they click ok then
have it undo any changes to the record and if they click cancel then have it
do nothing so they can then click the save button. But for some reason (and
it's driving me crazy) every time they click the close button it prompts them
with my message....even when nothing has changed with the record. The way I
want it set up is if nothing has changed with the current record then when
they click close have it just close without asking them anything. Can anyone
see what I'm doing wrong?

If Form.NewRecord Then

If MsgBox("Are you sure you want to exit without saving?",
vbOKCancel) = vbOK Then
Me.Undo
DoCmd.Close

Else
'don't do anything if cancel is clicked
End If
Else
If Me.Dirty = True Then

If MsgBox("Are you sure you want to exit without saving?",
vbOKCancel) = vbOK Then
Me.Undo
DoCmd.Close

Else
'don't do anything if cancel is clicked
End If
Else
DoCmd.Close
End If
End If
 
Ad

Advertisements

G

Graham Mandeno

Hi SS

Me.NewRecord will be true whenever the form is on a new record, whether or
not the user has started entering data.

The only thing you need to check for is Me.Dirty, so delete all the code up
to the Else before "If Me.Dirty", and also the last "End If".
 
L

Laura M. Daugherty

Secret Squirrel said:
I'm trying to use a popup message when a users clicks the close button on
my
form to ask them if they want to exti without saving. If they click ok
then
have it undo any changes to the record and if they click cancel then have
it
do nothing so they can then click the save button. But for some reason
(and
it's driving me crazy) every time they click the close button it prompts
them
with my message....even when nothing has changed with the record. The way
I
want it set up is if nothing has changed with the current record then when
they click close have it just close without asking them anything. Can
anyone
see what I'm doing wrong?

If Form.NewRecord Then

If MsgBox("Are you sure you want to exit without saving?",
vbOKCancel) = vbOK Then
Me.Undo
DoCmd.Close

Else
'don't do anything if cancel is clicked
End If
Else
If Me.Dirty = True Then

If MsgBox("Are you sure you want to exit without saving?",
vbOKCancel) = vbOK Then
Me.Undo
DoCmd.Close

Else
'don't do anything if cancel is clicked
End If
Else
DoCmd.Close
End If
End If
 
T

tina

Graham answered your question, SS. just an additional note, if i may. as a
user, i'd find the message and OKCancel buttons ambiguous, unless it was
explained to me which did what. it might be clearer to the user if you
adjusted it to

If MsgBox("Do you want to save this record?", _
vbYesNo) = vbNo Then
Me.Undo
DoCmd.Close
End If

if the user is more likely to want to cancel than to save, you could 1)
change the default button to the No button, OR 2) change the message to "Do
you want to cancel the changes to this record?".

hth
 
S

Secret Squirrel

Thank you for the input Tina. I will discuss that with my group and see how
they'd like it set up. Appreciate your input!

SS
 
Ad

Advertisements

T

tina

you're welcome :)


Secret Squirrel said:
Thank you for the input Tina. I will discuss that with my group and see how
they'd like it set up. Appreciate your input!

SS
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top