Results 1 to 13 of 13
  1. #1
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Alert if record not saved (2002)

    Hi,

    Is there a way to see if a form has been saved before a form is closed? I'd like to put a prompt behind the close button that will ask the user if they wish to save the record before exiting. It should only come up if the record was not saved. If the user saves the record and then clicks the exit button there should not be a message, but rather the form should just close.

    Thanks,
    Leesha

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Alert if record not saved (2002)

    Normally, closing a form will always save the record.
    If you want to check this use this in the Unload event of the form:
    If Me.Dirty Then
    MsgBox "The record is not saved"
    Cancel = True
    End If

    But as I say, the message box will never appear, as the record is saved before the unload event
    Francois

  3. #3
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Alert if record not saved (2002)

    OK, then with that new piece of knowledge, what would your suggestion be for the scenerio when someone starts to enter data and then decides against it. I'm trying to keep the table from having incorrect data. I've got staff who start to fill out a form, and then exit, not wanting the info saved but its saved anyway. Now I know why so that is a help! I appreciate the explanation. How do I prevent this?

    Leesha

  4. #4
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Alert if record not saved (2002)

    Then you have to check every field you want them enter data in the Before Insert event of the form.
    If this is not the case, then you can use code to ask them if they want to abort the entry and use the Me.Undo function of the form before closing it.

    You can also learn them to press the escape key twice, to undo an entry (once to undo the field they are in, and a second time to undo the form)
    Francois

  5. #5
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Alert if record not saved (2002)

    Hi,

    Teaching them not to make the mistake of hitting exit without undoing their work is useless. There is always the user that is not paying attention. Presently I have the this code behind the close button:

    If MsgBox("Do you wish to save this record before exiting?", _
    vbYesNo + vbQuestion) = vbYes Then

    DoCmd.RunCommand acCmdSaveRecord
    DoCmd.Close
    Else:

    DoCmd.Close
    End If

    I thought it did the trick until a staff person started complaining "why does the form ask if I want to save the record if its already saved?" My goal is to keep the msgbox from prompting if the record was already saved.

    Leesha

  6. #6
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Alert if record not saved (2002)

    Try this code :
    If Me.Dirty then
    If MsgBox("Do you wish to save this record before exiting?", _
    vbYesNo + vbQuestion) = vbYes Then
    DoCmd.RunCommand acCmdSaveRecord
    Else:
    Me.Undo
    End If
    End if
    DoCmd.Close
    Francois

  7. #7
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Alert if record not saved (2002)

    Wow! That is exactly what I was looking for.

    Thanks,
    Leesha

  8. #8
    3 Star Lounger
    Join Date
    Jun 2002
    Location
    Nottingham, Nottinghamshire, United Kingdom
    Posts
    257
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Alert if record not saved (2002)

    Leesha

    Sorry to jump in here. Of course the solutions offered work fine. I approach all data entry in a rather different way. Instead of offering users the chance to add a new entry direct into a bound form, all my data entry is via unbound forms populated by unbound text boxes. I provide a Cancel button which just closes the form and a Save button.

    The code behind the Save button can apply considerable data entry checking, far more complex than that allowed with normal data entry, and the record is only saved once the data has been checked, formatted or whatever else I need, any errors simply cause the code to exit back to the form. The data is saved by VBA field by field, not automatically.

    One benefit of this type of data entry form is that data can be collected for several records/tables at the same time and all saved properly linked. But you have to do all the work yourself through VBA.

    Complicated edit forms can also be constructed which load in existing data, allow users to play with it but not save it back until a Save button is pressed. Again considerable checking and formatting can be done.

  9. #9
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Alert if record not saved (2002)

    Hi David,

    Thank you for your post and imput. You provided some interesting food for thought and the timing is perfect as I'm about to start building a new data entry form and your approach would solve a lot of the headaches/errors I can forsee coming from the form due to incorrect data entry and saving.

    Thanks!

    Leesha

  10. #10
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Alert if record not saved (2002)

    Keep in mind that unbound forms, while powerful, require extensive code to read records into the form and write them back to the recordset. The developer has to handle in code all the things that Access handles automatically in a bound form.
    Charlotte

  11. #11
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Alert if record not saved (2002)

    Very good point and one I will certainly keep in mind before attempting this especially since coding beyond the basics is certainly NOT my strong point!

    Leesha

  12. #12
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Alert if record not saved (2002)

    Edited by HansV to provide description for extremely long URL - see <!help=19>Help 19<!/help> for instructions

    Hi Leesha

    I struggled with the appropriate User Interface for add, edit and delete buttons until I came across the following:

    If your starting a new project check it out.

    However, you have to be a a $149US per year subscriber (a bargin) to Pinnacle Publishing, Smart Access

    HTH

    John

    1. Access Application Development Documentation
    Issue: SmartAccess August 2002
    Author: Dennis Schumaker

    2. User Interface Standards

  13. #13
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Alert if record not saved (2002)

    Thanks!! I appreciate to lead.

    Leesha

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •