[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

close a form with or without saving changes

Posted on 2008-01-29
15
Medium Priority
?
440 Views
Last Modified: 2012-06-21
I would like to be able to advise the user when they close a form and there has been changes on if they want to save the changes or not
0
Comment
Question by:Frank Freese
  • 6
  • 6
  • 2
  • +1
15 Comments
 
LVL 3

Expert Comment

by:avbsql
ID: 20772588
Ru looking to let the user know or have a pop up message to give an option to save or not save the changes...is that the question?
0
 

Author Comment

by:Frank Freese
ID: 20772624
When a form is closed a pop up message would appear asking them if they want to save the record. If the say no then no record is written
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 20772726
is this a bound form?
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 75
ID: 20772784
Private Sub Form_UnLoad(Cancel As Integer)

If Me.Dirty = True Then
       If MsgBox ("Do you want to save the changes?", 20,Me.Caption) = vbYes Then
           Me.Dirty = False
       End If
End If
End Sub
0
 
LVL 75
ID: 20772793
Mod:

Private Sub Form_UnLoad(Cancel As Integer)

If Me.Dirty = True Then
       If MsgBox ("Do you want to save the changes?", 20,Me.Caption) = vbYes Then
           Me.Dirty = False
       Else
           Me.Undo                 ' **** ADD THIS
       End If
End If
End Sub
0
 

Author Comment

by:Frank Freese
ID: 20772930
The form is bound. Some of the fields have default values and those controls are locked. The me.dirty=true is false because the user did not actually enter any data themselves.
0
 
LVL 75
ID: 20772959
If not data was entered, what is there to save ?

mx
0
 

Author Comment

by:Frank Freese
ID: 20772982
the defaults arew being saved
0
 
LVL 75
ID: 20773012
Defaults are not Saved unless the record is made Dirty by and Edit of some bound field.

mx
0
 

Author Comment

by:Frank Freese
ID: 20773061
i stand corrected. however, when I did put data in the form_unload me.dirty came back as false not true and the msgbox was not executed.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 20773137
fh_freese,
how are your users close the form? do you have command button for this?
0
 

Author Comment

by:Frank Freese
ID: 20773156
yes.

Docmd.close
Docmd.openform "Main Menu"
0
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 2000 total points
ID: 20773169
"however, when I did put data in the form_unload me.dirty came back as false not true and the msgbox was not executed."

Then the record is already being save via some other way, like going to a new record or clicking into a subform (if there is one) ... or click Shift+Enter.

In fact, It's probably being saved as the result of clicking the X button on the form ... I just came across this recently.  You may need a Close button ... and the put that code in the Close button Click event.

mx
0
 
LVL 75
ID: 20773181


Private Sub btnClose()

If Me.Dirty = True Then
       If MsgBox ("Do you want to save the changes?", 20,Me.Caption) = vbYes Then
           Me.Dirty = False
       Else
           Me.Undo                 ' **** ADD THIS
       End If
End If
docmd.Close acForm, me.name
End Sub

Also ... turn off the Close X button on the form property sheet.
0
 

Author Closing Comment

by:Frank Freese
ID: 31426191
thanks. hope not to revisit this. much appreciated.
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have had my own IT business for a very long time. I started mostly with hardware and after about a year started to notice a common theme. I had shelves with software boxes -- Peachtree, Quicken, Sage, Ouickbooks -- and yet most of my clients were…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Hi, this video explains a free download that you can incorporate into your Access databases, or use stand-alone for contact management. Contacts -- Names, Addresses, Phone Numbers, eMail Addresses, Websites, Lists, Projects, Notes, Attachments…

640 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question