Close Form Event

I have a AC2003 bound form.  The condition I'm trying to capture is if the 
user modifies any item on the form and they close the form without saving 
changes.  Simple...right?  I found out that Form_Close doesn't work so I 
tried the following code in the Form_Unload event and that isn't working 
either.  It does not even trigger the event.  Can someone please tell me what 
I'm doing wrong?  I would be much appreciated.

Private Sub Form_Unload(Cancel As Integer)
    If Me.btnSave.Enabled Then
        Dim strMsg As String
        strMsg = strMsg & "Save Changes?" & Chr(13) & Chr(13)
        If MsgBox(strMsg, vbQuestion + vbYesNo, "Please Confirm!") = vbYes 
Then
            DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , 
acMenuVer70
        Else
            Cancel = True
        End If
    End If
End Sub

0
Utf
6/5/2010 3:03:52 AM
access 16762 articles. 2 followers. Follow

4 Replies
1347 Views

Similar Articles

[PageSpeed] 13

You can code the save button like this:

Private Sub btnSave_Click()
Dim strMsg As String
        strMsg = strMsg & "Save Changes?" & Chr(13) & Chr(13)

If Me.Dirty = True Then
If MsgBox(strMsg, vbQuestion + vbYesNo, "Please Confirm!") = vbYes Then
    Me.Dirty = False
Else
    Me.Undo
End If
End If
End Sub

You will need some error handling to trap errors if something stops the 
save, for example a required field missing.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia

"PeterM" <PeterM@discussions.microsoft.com> wrote in message 
news:E5B3554A-93AE-4BA9-8D54-0E080E8815F4@microsoft.com...
>I have a AC2003 bound form.  The condition I'm trying to capture is if the
> user modifies any item on the form and they close the form without saving
> changes.  Simple...right?  I found out that Form_Close doesn't work so I
> tried the following code in the Form_Unload event and that isn't working
> either.  It does not even trigger the event.  Can someone please tell me 
> what
> I'm doing wrong?  I would be much appreciated.
>
> Private Sub Form_Unload(Cancel As Integer)
>    If Me.btnSave.Enabled Then
>        Dim strMsg As String
>        strMsg = strMsg & "Save Changes?" & Chr(13) & Chr(13)
>        If MsgBox(strMsg, vbQuestion + vbYesNo, "Please Confirm!") = vbYes
> Then
>            DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
> acMenuVer70
>        Else
>            Cancel = True
>        End If
>    End If
> End Sub
> 


0
Jeanette
6/5/2010 3:45:12 AM
I don't think I've explained the problem clearly.  I have the save button 
setup the way you define in your example.  How do I capture if the user 
changes a bound item on a form and tries to close the form without clicking 
on the save button first.  There is no close button on the form, a form is 
closed by a parent form when another form is opened.  I need to determine 
when the form is closed but still is dirty.  THe unload and close events 
don't work in that situation.

"Jeanette Cunningham" wrote:

> You can code the save button like this:
> 
> Private Sub btnSave_Click()
> Dim strMsg As String
>         strMsg = strMsg & "Save Changes?" & Chr(13) & Chr(13)
> 
> If Me.Dirty = True Then
> If MsgBox(strMsg, vbQuestion + vbYesNo, "Please Confirm!") = vbYes Then
>     Me.Dirty = False
> Else
>     Me.Undo
> End If
> End If
> End Sub
> 
> You will need some error handling to trap errors if something stops the 
> save, for example a required field missing.
> 
> 
> Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
> 
> "PeterM" <PeterM@discussions.microsoft.com> wrote in message 
> news:E5B3554A-93AE-4BA9-8D54-0E080E8815F4@microsoft.com...
> >I have a AC2003 bound form.  The condition I'm trying to capture is if the
> > user modifies any item on the form and they close the form without saving
> > changes.  Simple...right?  I found out that Form_Close doesn't work so I
> > tried the following code in the Form_Unload event and that isn't working
> > either.  It does not even trigger the event.  Can someone please tell me 
> > what
> > I'm doing wrong?  I would be much appreciated.
> >
> > Private Sub Form_Unload(Cancel As Integer)
> >    If Me.btnSave.Enabled Then
> >        Dim strMsg As String
> >        strMsg = strMsg & "Save Changes?" & Chr(13) & Chr(13)
> >        If MsgBox(strMsg, vbQuestion + vbYesNo, "Please Confirm!") = vbYes
> > Then
> >            DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
> > acMenuVer70
> >        Else
> >            Cancel = True
> >        End If
> >    End If
> > End Sub
> > 
> 
> 
> .
> 
0
Utf
6/5/2010 5:00:58 AM
On Fri, 4 Jun 2010 22:00:58 -0700, PeterM <PeterM@discussions.microsoft.com>
wrote:

>I don't think I've explained the problem clearly.  I have the save button 
>setup the way you define in your example.  How do I capture if the user 
>changes a bound item on a form and tries to close the form without clicking 
>on the save button first.  There is no close button on the form, a form is 
>closed by a parent form when another form is opened.  I need to determine 
>when the form is closed but still is dirty.  THe unload and close events 
>don't work in that situation.

Use the form's BeforeUpdate event. It will fire if any field value is changed
and any action is taken that would save it (such as closing the form, pressing
Shift-Enter, etc.) You can set the value of a public variable in the
legitimate "close" button and check that variable's value in the BeforeUpdate
event; if you don't want to save the record, issue a message and set the
event's Cancel parameter to True.
-- 

             John W. Vinson [MVP]
0
John
6/5/2010 5:41:39 AM
Thanks John!

"John W. Vinson" wrote:

> On Fri, 4 Jun 2010 22:00:58 -0700, PeterM <PeterM@discussions.microsoft.com>
> wrote:
> 
> >I don't think I've explained the problem clearly.  I have the save button 
> >setup the way you define in your example.  How do I capture if the user 
> >changes a bound item on a form and tries to close the form without clicking 
> >on the save button first.  There is no close button on the form, a form is 
> >closed by a parent form when another form is opened.  I need to determine 
> >when the form is closed but still is dirty.  THe unload and close events 
> >don't work in that situation.
> 
> Use the form's BeforeUpdate event. It will fire if any field value is changed
> and any action is taken that would save it (such as closing the form, pressing
> Shift-Enter, etc.) You can set the value of a public variable in the
> legitimate "close" button and check that variable's value in the BeforeUpdate
> event; if you don't want to save the record, issue a message and set the
> event's Cancel parameter to True.
> -- 
> 
>              John W. Vinson [MVP]
> .
> 
0
Utf
6/6/2010 3:18:05 AM
Reply:

Similar Artilces:

ThisWorkbook.Close question
Please take a look at the code below: Public Sub DumbFoo ( ) ThisWorkbook.Close() Sheet1.Range("A1").Value = -1 ThisWorkbook.Save() End Sub Is it safe to assume that the code below the "ThisWorkbook.Close()" line will NOT be executed??? My question is basically: Does all VBA code stop executing once a .Close() function is called??? Thank you! I don't believe the code would execute at all because of the parentheses after Close. It would throw an error an tell you that something is missing, or type mismatch. But, if you did...

How to Enable Close(cross) button of MB_YESNO messagebox
Hi, I want to enable the close(cross) button in the right corner of YESNO message box. Can anybody tell me how to do this. Klic. "Klic" <rohit.turambekar@gmail.com> wrote in message news:1186120969.045121.287770@i13g2000prf.googlegroups.com... > I want to enable the close(cross) button in the right corner of YESNO > message box. > Can anybody tell me how to do this. Why? If there is a valid answer other than yes or no, then how about a yes/no/cancel message box in which (I would guess) the x button is equivalent to cancel. That would be more standard. Da...

closing
What's the best way to close for the day? Making a backup is a given, but what about the computer? Is it better to shut everything off every day, or is it less wear and tear on the computer to leave it on all the time? Any thoughts on this would be appreciated. Craig That's a matter of preference really. Personally I always turn off my rigs at home when I'm done with them. At the store we leave most of ours on 24/7. We've done it for years with no issues. Our register must be left on as it does automatic backups to a tape drive every night. I'd set your monitors ...

Outlook closes and closes
Hi I have a strange bug. Windows XP Sp2 and outlook from office 20003 with all service packs applied. When I start outlook from windows out of standby postion, outlook immediately after the splash screen closes without reporting any errors in the eventlog or in any other log. If I start outlook the 10th time (or so) it stabilizes and does not close anymore and everything works again. info: My machine is fully patched and I am well known with keeping things healthy. Outlook.exe Version: 11.0.6353.0 Any ideas what to do? Thanks... try the detect and repair in the help menu. >----...

OWA forms
Hello, I have over 300 OWA users who wish to have the capability to request vacation time using a form similar to outlook vacation form using OWA, Is this possible? and if so, is there a procedure or an example I can follow to create such forms? Thank you in advance. That's not an Outlook question, I'm afraid, since desktop Outlook forms = do not translate to OWA at all. Exchange development docs start at = http://msdn.microsoft.com/exchange/ with discussions in the = microsoft.public.exchange.development newsgroup or on the Web at = http://forums.microsoft.com/TechNet/ShowForu...

Help
When creating or fowarding an e-mail message using outlook 2000, scrolling through my "recipients" list (contacts) causes the program to close unexpectedly. So, I click "new", click "to", switch to my "contacts" list, and as I scroll through the names, the program just closes. Is there a possibility that one of my contact records is corrupt? I have opened all of my contacts and saved them without an error. This problem developed shortly after the install of Office 2000's calender update, and basic security update. I have since fully u...

Excel Form and message box
Hi there, I'm running Excel 2000. I am just learning so please excuse my questions if they sound simple. To put this as simply as possible I have a spreadsheet of children's names. I've created a form that is activated by a control button. What I want to do is choose a child's name from the combo box and eventually delete that child from the spreadsheet. I have an "are you sure" type msgbox but cannot get the yes/no side of it functioning correctly. I've worked on this for hours and have just given up. This is my code so far: Private Sub cboRemChild_...

Forms to Public Folder from other Organization are blank
Our company has two Exchange organizations (don't ask). Organization A has forms published in the Organizational Forms Library. Organization B does not. User A moves from Org A to Org B and wants to use a form they have used before in Org A. This form posts to a public folder in Org A. Since the form is not published in Org B they use a form that was previously forwarded to them and then forward it back to the public folder. However, when it arrives at the public folder there is no form and the email is blank. If the same form is forwarded to a user or DL in Org A, it shows up as ex...

Updating a form if field has been removed so that I don't get a me
Hi I have created a form. Due to modifications to the form, I no longer need a field which I have included in the original form. Before I deleted the field, I had made a back up of my database. When I delete the field, let's call it "ProductCodeOld", whenever I open up the database, I get a text box saying that the "ProductCodeOld" is not in the form or words to that effect. How do I remove a field from a form without this type of message appearing? Thank you in advance. Forest8 - You may have code in the form that references the old field. ...

Opening up Access in Form View
I have created a form in Acces that is a main menu. When I click on the database icon I want the database to open in the main menu form. How do I do that? Thank you! For pre-2007 versions select Tools | Startup on the main database menu bar, and then select the relevant form as the Display Form/Page property. I can't speak for 2007, but I imagine it will be broadly similar. Ken Sheridan Stafford, England Alaska1 wrote: >I have created a form in Acces that is a main menu. When I click on the >database icon I want the database to open in the main menu form. Ho...

Auto-close Quotes when Closing Opportunity
We would like the ability to close an opportunity and have it ask if you want to close all the associated quotes. Right now, it says you can’t close the opp until you close all the open quotes and you have to each one of those one by one. Barring that, if we could select multiple quotes and click on a menu item (Close all selected quotes), that would be most useful. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not ...

Workflow Rule -> Closing Activity
I set up a Manual Workflow Rule for Contacts to close out Holiday Season cards sent. The rule uses a condition to check for Contacts with cards sent and then Creates an Activity to add to each of the appropriate Contacts for future reference. What else do I need to do to close out all of activites rather than 1 at a time? Here is the workflow rule if that helps: if Contact.holidaycardlist = 1 then Letter: Send Holiday Card endif -- Dan W Systems Engineer Denver, CO ...

Data file not closed properly #3
I saw several post regarding this, but none had any answers, so I starting a new post. There is also nothing in the KB about this. Since othe people are having the same problem Microsoft should take a look at it. I get the message "The data file 'Personal Folders" was not closed properly" every time I close Outlook 2003. It runs a quick check/fix and starts up fine. I am running XP pro w/ SP-2. Outlook 2003 w/ SP-1 All patches and updates are current. My notebook was just rebuilt for so I could get a clean slate for the office 2003 install, (reformat drive and new ins...

double-click to new form in Access 2003
An application (which I am not familiar with) was written in Access 2002. There is a form with a subform where double-clicking on a row is supposed to go to another form using the information from the selected row in the subform. The user's Access has been upgraded to Access 2003 and double-clicking now brings him to an empty form rather than the next form according to the fields of the selected row. I have Access 2002. However on my computer, double-clicking doesn't do anything. The Action on On Dbl Clk on the fields in the Details section of the subform of the main form is OpenF...

Outlook2003 open and closed immediatly
I checked event log, nothing. And this happened when I just reboot my machine and first time tried to open Outlook, still same problem. But I found, when I double click anywhere in the Outlook Windows even it only gave me 0.5 second, then it won't close. Andy -------------------------------------------------------------- >>Look in task manager - processes, and see if multiple >>instances are running. If so, end all of them and try >>starting again. I had similar problem w/user, posted >>above. >>>>>-----Original Message----- >>>>>My O...

How to change the unchangeable 18 hour event reminder?
I've seen it posted quite a few places that it can't be done but that's history. New things are always happening. So... How can I change the default "18 hours" reminder when I create an all day event? More importantly... how can I change it on all of the installations in my network. It has become a minor frustration when the CEO sends out an all day meeting request (event) with a 2 day reminder and very recipient sees the 18 hour default. Yes, I know there are bigger problems out there... world hunger and flipping plug receptacles so the "face" is right-sid...

Outlook Closes After Closing an Email
When I click the 'X' to close an email after reading it, Outlook closes (or tries to close, but I get a warning because I have templates in my Outbox). This only seems to happen when I close a new email. I have Outlook 2003. Thank you. ...

Display Count of records from subform on Main form
I need to show a count of records for doc on main form. Doc info is on main form and list of pts is on subform. I have entered an unbound text box on the main form and have tried DCount, ABSSum and Count all I get is 0. This is what I have entered: =DCount([ID]) or ABS(Sum([myfrom].[ID]) and =Count([ID]). Thank you in advance for any help you can provide. Thank you. Try it this way: Create a query with the needed table. Add the id-field to the grid. Total it by Count. Save the query and on the form you place an unbound field. In VBA you can do a Dlookup for the one field in the q...

YE Closing Procedures
The year end closing procedures need to be more efficient and user friendly. For example, the payables and receivable management is date sensitive except for amounts since last close, vendor yearly summary etc. These modules should be fully date sensitive and the ability to enter into multiple years without caveats should exist. Year end is stressful enough ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the b...

Permissions / Closing MDB left open
I need to learn how to create - well, I'm not actually sure what I need to learn... Let me explain: I'm a surgical resident. I've been working on an Access MDB as a patient census - for day-to-day management including tables, queries, and forms that print based on room number or service. Everything is setup as needed in the local file. I've been working on the content of the database on and off for a year. Recently, before I can implement my project, I realized I have a very big challenge to overcome related to usage of the file. Now, to complicate my iss...

Promote Form Properties Greyed Out
Hi I have created a form in infopath 2007 that is to be emailed and I would like to be able to view the properties I have selected in the form folder. I can see the headings of the properties but none of the data is being shown. When I right click on the form folder there is a check box that reads "Promote form properties and display the data as columns in a new view" however this option is greyed out. I have tried creating a Personal Files Folder but the check box still does not become available. Is there a workaround for this or another way for the data to be shown in...

Formula syntax
I have a number of points on my x-y scatter chart requiring the plottin of a non-linear trend line based on the following relationship (I have two data series column for values mmax and t2 in my worksheet). mmax = 16.68-0.81arctan [log10(200/t2)-0.98] ------------------------ [ 0.19 ] I have tried to follow the syuntax rules to assemble a spreadshee formula including inserting the fx of ATAN and Log10 where needed bu the formula is still rejected as incorrect. Any ideas plaese? BigBo -- BigBo ----------------------------------------------------------------------- Big...

Closed account not so closed?
Hi All... I have (had) an investment account with E*Trade, which I have since closed. In MS Money 2006, I have it as "Account Is Closed", in the account list. There are a few weird things going on: 1. When I go into the account list, this account appears in gray with $0.00 next to it, but the "To Review" column has "Update in Progress" in it. This account is definately not part of my regular online updates (though when it was active, it was). 2. When I click into this account, 2 securities are listed. Neither one of them has Quantity or Cost Basis,...

Closing Excel #2
I have inherited an App desigend by an ex employee Sometimes the program leaves Excel in the task manager The programe uses various routines and calling various functions that define Excel sheets etc (badly named) I'm finding it hard to follow (my 1st experince of .NET) is there a way to KILL any Excel instence when exiting the program. I have come across some posts about GC (garbage collection) like this System.Runtime.InteropServices.Marshal.ReleaseComObject(oXLWsheet) oXLWsheet = Nothing 'System.Runtime.InteropServices.Marshal.ReleaseComObject(oXLWs) oXLWs = Nothing oBook.Clos...

when closing outlook favourite files disappear
When I create a favourite file by right clicking it creates ok and appears in the favouites section. After closing and reopening outlook the file disappears from the favourites section Bummer! -- Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. How to ask a question: http://support.microsoft.com/KB/555375 "ceh" <ceh@discussions.microsoft.com> wrote in message news:9C6E3908-E47D-4398-B12F-376AC9A7A8F8@microsoft.com... > When I create a favourite file by right clicking it creates ok and appears > in > the favouites sec...