Results 1 to 7 of 7
  1. #1
    dollor is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2011
    Posts
    2

    Cool Close form withour saving / skip error message

    Hello everybody,


    my name is Christian and I just started experimenting with Access to create my first database.

    I have a problem I cannot google an answer to:

    I have a form that creates a new recordset when it is opened and populates some data.

    Now I wanted to give the possibility to close it without saving the new recordset. I used the following:

    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    If MsgBox("Save changes?", vbYesNo, "Save?") = vbNo Then
      Me.Undo
      Cancel = True
    End If
    End Sub
    Two problems:
    1> It counts up my autonumber. That is more cosmetical and not really a problem, but can I create a new recordset "virtually" that is only really created when I close the form?
    2> After my safe message and clicking "no", access also displays a message "You can't save this record at this time...". Can I disable this message (because I already decided I don t want to save on the first form)

    Thank you

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    you probably can't find a solution on google because this is a fundamental piece of knowledge that most people have. I assume this is a bound form? and I further assume that you're not aware that bound forms update automatically, even without saving the form??

    and I even further assume that you know that the error message you're referring to is relevant to another issue within the database?? for instance, if validation is required in one of your fields and you attempt to close the form, the reason that error will pop up is because the form saves itself everytime you close it.

    more than likely, that is probably the reason for it's appearance.

  3. #3
    dollor is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2011
    Posts
    2
    your assumptions regarding the bound form are right, if I understand you right, that "virtual recordset" is not possible then or in other words, the method of Me.Undo only works on changes made to the form but not on the recordset behind it?

    And yes, I have validation for some of the fields;

    what would be a proper way to give for a "changed my mind' not save?

    Background: The form is to allow a user to create a revision for a certain design. In case the user accidentaly clicks on the new revision button or he changes his mind while inputing the data in the open form, I want him to be able to cancel that.

  4. #4
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by dollor View Post
    what would be a proper way to give for a "changed my mind' not save?
    ME.UNDO undoes changes to the current record that is being manipulated. ME.UNDO becomes irrelevant (I believe) when the user moves to a new record. I believe, but don't quote me, that ME.UNDO is meant to undo ALL changes that are made to the current record after it's been dirtied. In other words, after any bound data has been altered.

    Now, a lot of people talk about this and CANCEL = TRUE. The CANCEL concept in VBA is different than ME.UNDO in that it formally cancels the new record that has been created, if that scenario is applicable to the user. Now, I believe that's the case, but again I'm not 100% sure. I don't even work with Access anymore, so I've forgotten specific things like this.

    The proper way, ask you've asked, is to use a button that says "current record has changed. save changes?". and obviously offer the user a YES/NO scenario.

    If you don't do that and the user closes the form anyway, Access is going to make that same thing happen, so you may as well just disappear the control box and close button on the form and offer the user a manual alternative that your scripts have complete control over.

  5. #5
    kennejd is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    188
    You could use an unbound form.....that would give you the most control over your saves and so forth. But that would also require quite a bit of code to do the stuff access does automatically with a bound form.

  6. #6
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by kennejd View Post
    You could use an unbound form.....that would give you the most control over your saves and so forth.
    I'm gonna disagree wholeheartedly with that. Not much truth here, especially for beginning Access users that need to make use of things like macros for execution purposes.

    For this person, I would not consider this an idea.

  7. #7
    kennejd is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    188
    True...an unbound form is not the best solution for a beginner.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 03-14-2011, 03:42 PM
  2. Access Form- Save/Close Button error
    By Ashe in forum Forms
    Replies: 3
    Last Post: 02-10-2011, 01:01 PM
  3. Replies: 3
    Last Post: 11-22-2009, 07:46 AM
  4. Unable to close Query without saving
    By jhrBanker in forum Access
    Replies: 0
    Last Post: 06-08-2009, 05:09 PM
  5. skip "run query anyway" message
    By Artemis in forum Programming
    Replies: 1
    Last Post: 09-18-2008, 12:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums