How do I make sure that the user has saved the record before closing it

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Hulas
    New Member
    • Mar 2008
    • 18

    How do I make sure that the user has saved the record before closing it

    Guys I have a form with a 'save' and 'close form' button. How do I make sure that the user has saved the record before closing it. What I am looking for is that I want to modify the 'close form' button such that if a user selects the 'close form' button without saving the record, it will pop up a box that will say something like this" You haven't saved your record, do you want to save now;Yes or No"

    Thanks you for considering my request.
    Hulas
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by Hulas
    Guys I have a form with a 'save' and 'close form' button. How do I make sure that the user has saved the record before closing it. What I am looking for is that I want to modify the 'close form' button such that if a user selects the 'close form' button without saving the record, it will pop up a box that will say something like this" You haven't saved your record, do you want to save now;Yes or No"

    Thanks you for considering my request.
    Hulas
    The logic would be something like this:
    [CODE=vb]
    Dim strMsg As String

    strMsg = "Record has not been Saved, Save now?"

    If Me.Dirty Then
    If MsgBox(strMsg, vbQuestion + vbYesNo + vbDefaultButton 1, "Record Not Saved") = vbYes Then
    DoCmd.DoMenuIte m acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
    Else
    DoCmd.DoMenuIte m acFormBar, acEditMenu, acUndo, , acMenuVer70
    End If
    End If[/CODE]

    Comment

    • nico5038
      Recognized Expert Specialist
      • Nov 2006
      • 3080

      #3
      Hmm, I use in this case another approach.
      Getting a message to save is for me annoying for the users, I just offer them two buttons:
      [OK] (for saving) and [Cancel] (for aborting the update).
      Finally on an update form I sometimes add a [Reset] button, thus enabling the user to return to the original content. For this button this code can be used:
      [code=vb]
      If Me.Dirty then
      Me.Undo
      End If
      [/code]

      Nic;o)

      Comment

      • missinglinq
        Recognized Expert Specialist
        • Nov 2006
        • 3533

        #4
        And what if they simply move to another record or close the form, Nic;o)? The record may still be saved, depending on whether there are required fields that are/aren't filled, regardless of the user's intentions.

        Linq ;0)>

        Comment

        • nico5038
          Recognized Expert Specialist
          • Nov 2006
          • 3080

          #5
          I only show one (filtered) record Linq, so moving won't work :-)
          Closing the form with the [X] can be disabled, thus leaving the user only a choice between [OK] and [Cancel].
          The [OK] button will trigger the field testing for mandatory and/or relationships.

          Small sample at:
          Latest news coverage, email, free stock quotes, live scores and video are just the beginning. Discover more every day at Yahoo!


          Nic;o)

          Comment

          • missinglinq
            Recognized Expert Specialist
            • Nov 2006
            • 3533

            #6
            That's fine in your rather limited application, Nic;o), but that's not the way most people do it! You should really have qualified your answer so that the OP and others reading the thread will understand that in a form where more than one record can be viewed/added/edited your answer won't work.

            Linq ;0)>

            Comment

            • Hulas
              New Member
              • Mar 2008
              • 18

              #7
              It seems like I wasn't to specific with my request. You can consider any form with bunch of records to fill, that has a 'Save' button and 'Close Form' button on it. After filling up all the records, if I hit 'Save' it will save the data entered. Likewise, if I hit 'Close Form', it will close the form (Note: I have programmed the Close Form button so that it will not save the data.). Now, how should I programme the 'Close Form' button such that if a user hadn't the saved the new record and hits the Close Form buttom by mistake, a message will pop up that will say something like this "You haven't saved your record, do you want to save now: Yes or No).

              Thank you for your help.
              Hulas

              Comment

              • Hulas
                New Member
                • Mar 2008
                • 18

                #8
                Thanks ADezii it works just fine

                Comment

                • Hulas
                  New Member
                  • Mar 2008
                  • 18

                  #9
                  Your code works fine with most of my forms, but it doesn't works where I have a combo box that pulls up more than one record. Any suggestions on that.

                  Thank you for your help.
                  Hulas

                  Comment

                  • nico5038
                    Recognized Expert Specialist
                    • Nov 2006
                    • 3080

                    #10
                    Originally posted by missinglinq
                    That's fine in your rather limited application, Nic;o), but that's not the way most people do it! You should really have qualified your answer so that the OP and others reading the thread will understand that in a form where more than one record can be viewed/added/edited your answer won't work.

                    Linq ;0)>
                    Hmm, did you inspect the way you're working with Access ?
                    1) Select the Object (e.g. form)
                    2) Select the Action (Edit/Open/etc.)

                    The proposed way is used in many applications, including Access.

                    Nic;o)

                    Comment

                    • nico5038
                      Recognized Expert Specialist
                      • Nov 2006
                      • 3080

                      #11
                      Originally posted by Hulas
                      It seems like I wasn't to specific with my request. You can consider any form with bunch of records to fill, that has a 'Save' button and 'Close Form' button on it. After filling up all the records, if I hit 'Save' it will save the data entered. Likewise, if I hit 'Close Form', it will close the form (Note: I have programmed the Close Form button so that it will not save the data.). Now, how should I programme the 'Close Form' button such that if a user hadn't the saved the new record and hits the Close Form buttom by mistake, a message will pop up that will say something like this "You haven't saved your record, do you want to save now: Yes or No).

                      Thank you for your help.
                      Hulas
                      Updating a group of records "in one go" is only possible by using a temp table.
                      1) Put the selection in the temp table
                      2) When Cancelled do nothing
                      3) When [Save] is pressed validate the records, drop the old record(s) using the selection filter and insert the temptable rows.
                      Access uses a record by record save schema for making sure not too much data is lost when an update goes wrong...

                      Nic;o)

                      Comment

                      Working...