Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 09-01-2004, 10:00 AM   #1
monkeytunes
Serf of the Jungle
 
monkeytunes's Avatar
 
Join Date: Jun 2004
Location: Seattle, WA, USA
Posts: 120
Thanks: 0
Thanked 0 Times in 0 Posts
monkeytunes is on a distinguished road
Save Button versus Save safety net

Because my users like the standard safety net of "Do you wish to save these changes?", I used some code from this post in the Before Update event of many of my forms.

However, many of the users, being proactive, conscientious sorts, like to Save on their terms. So I put in a command button using the wizard for saving records.

When the button is pressed, it immediately pops up the window that says "Do you wish to save these changes?", instead of merely saving the record. Is there a workaround so that when the button is pressed, the record is saved, but if the form is closed when the record is dirtied, the warning pops up?

monkeytunes is offline   Reply With Quote
Old 09-01-2004, 10:13 AM   #2
The_Doc_Man
Happy Retired Curmudgeon
 
Join Date: Feb 2001
Location: Suburban New Orleans, LA, USA
Posts: 14,547
Thanks: 92
Thanked 1,680 Times in 1,559 Posts
The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold
You'll have to look up the event firing order, but basically if the form is dirty, you have to cancel the attempt to close the form. Find whatever event in the "close" chain has a Cancel option. In that one, test Me.Dirty (which is TRUE if any record has been modified but not saved.) Put up a message box and cancel the closure event. (Or intervene and force a save with a DoCmd operation matching the code underlying your actual SAVE button.)
The_Doc_Man is offline   Reply With Quote
Old 09-01-2004, 10:21 AM   #3
monkeytunes
Serf of the Jungle
 
monkeytunes's Avatar
 
Join Date: Jun 2004
Location: Seattle, WA, USA
Posts: 120
Thanks: 0
Thanked 0 Times in 0 Posts
monkeytunes is on a distinguished road
Thanks for the quick reply Doc Man, but I'm really terrible with working out VB code on my own. I can usually (okay, a little less than "usually") decipher what's happening in pre-existing code, but if you've got a moment, I'm going to need more guidance with the advice you gave me.

Because this line -

Quote:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If MsgBox("Do you want to save the changes?", vbQuestion + vbYesNo, "Save?") = vbNo Then Cancel = True
End Sub
- is in the Before Update event of the Form, pressing the "Save Record" command button triggers it. Usually this Before Update works great, because a user might try to close the form or view a new record, and Access will jump and say "WAIT! Save?", but I want a users' deliberate pressing of the Save button to bypass the Before Update code.

I'm afraid users will find it annoying to press Save Record, and then get the message box asking "Do you wish to save?" I know I'd be answering back: "Of course I want to save! I just pressed the button, didn't I?!"

monkeytunes is offline   Reply With Quote
Old 09-01-2004, 10:34 AM   #4
ghudson
Newly Registered User
 
ghudson's Avatar
 
Join Date: Jun 2002
Location: USA
Posts: 6,199
Thanks: 1
Thanked 87 Times in 49 Posts
ghudson has a spectacular aura about ghudson has a spectacular aura about ghudson has a spectacular aura about
You are almost stuck in a loop. You might benefit from my A Better Mouse Trap? sample for that is my preferred way to ensure that a user has saved a modified record before they can move to another record or close the form. I created the method to prevent mouse wheel movement but it also keeps the user out of trouble to correctly save when needed.
__________________
.................................................. ......
Searching this forum or Microsoft.com or MSDN.com or Google is a great way to discover and learn the answers to your Access programming questions.

Well if it seems to be real, it's illusion...

I am using Access 2010 with Windows 7

The
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
function on this forum really does work.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

.................................................. ......
ghudson is offline   Reply With Quote
Old 09-01-2004, 11:23 AM   #5
monkeytunes
Serf of the Jungle
 
monkeytunes's Avatar
 
Join Date: Jun 2004
Location: Seattle, WA, USA
Posts: 120
Thanks: 0
Thanked 0 Times in 0 Posts
monkeytunes is on a distinguished road
Ghudson, thanks for the tip. I've actually looked at that DB before (since it was rated so highly, and with good reason), but I never thought of modifiying the code for this sort of thing...

But let me ask: Is the process really that complicated? I thought the functionality I was looking for was actually pretty standard - look at MS Word, or Excel, or pretty much any program out there:
  • You have a document, you change it, you save it, you close it without any hangups.
  • You have a document, you change it, you try to close it, the program says "You want to save before closing?"

Hell, Access already does that if you modify a form, and then try to close it without saving. I figure this functionality must be available somewhere...
monkeytunes is offline   Reply With Quote
Old 09-01-2004, 11:37 AM   #6
ghudson
Newly Registered User
 
ghudson's Avatar
 
Join Date: Jun 2002
Location: USA
Posts: 6,199
Thanks: 1
Thanked 87 Times in 49 Posts
ghudson has a spectacular aura about ghudson has a spectacular aura about ghudson has a spectacular aura about
You can not compare Excel or Word to Access. Access is a different beast.

The code you are using in the before update event is triggered when you click your custom save button because the record is dirty. You have to take the extra steps to account for that.

The method in my better mouse trap sample will allow you to do what you want. It is not hard to add my method to your db once you understand how it works. If there is a better way I would be interested to see it.
__________________
.................................................. ......
Searching this forum or Microsoft.com or MSDN.com or Google is a great way to discover and learn the answers to your Access programming questions.

Well if it seems to be real, it's illusion...

I am using Access 2010 with Windows 7

The
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
function on this forum really does work.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

.................................................. ......
ghudson is offline   Reply With Quote
Old 09-01-2004, 11:49 AM   #7
Rich
Guest
 
Posts: n/a
Try this


Last edited by Rich; 08-21-2008 at 07:03 AM.
  Reply With Quote
Old 09-01-2004, 12:12 PM   #8
monkeytunes
Serf of the Jungle
 
monkeytunes's Avatar
 
Join Date: Jun 2004
Location: Seattle, WA, USA
Posts: 120
Thanks: 0
Thanked 0 Times in 0 Posts
monkeytunes is on a distinguished road
Holy smokes, Rich, I think you've done it. Will this code function in 2000/2002 as is?
monkeytunes is offline   Reply With Quote
Old 09-01-2004, 12:17 PM   #9
Rich
Guest
 
Posts: n/a
I don't see why not, I don't have those versions to test it though

  Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump




All times are GMT -8. The time now is 06:10 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World