How to Undo a new record

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Gerry Goldberg
    New Member
    • Jul 2010
    • 11

    How to Undo a new record

    How can I undo the insertion of a new record using VBA?

    Thanks,

    Gerry Goldberg
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    You don't say where/how you want to do this, but

    Me.Undo

    is the syntax. On a new, unsaved record it will dump the entire record, on an existing, saved record it will dump any edits that have been made.

    Linq ;0)>

    Comment

    • mseo
      New Member
      • Oct 2009
      • 183

      #3
      Originally posted by Gerry Goldberg
      How can I undo the insertion of a new record using VBA?

      Thanks,

      Gerry Goldberg
      you have to provide enough details about your problem to help us provide good solution
      undo in mainform or subform?

      Comment

      • Gerry Goldberg
        New Member
        • Jul 2010
        • 11

        #4
        In this particular case, I just want to be able to get rid of a new record that has not been saved. Normally, this occurs if the user accidently creates a new record. Right now, this is only a problem in a form without any subforms.

        I appreciate your help. It looks like the "me.undo" will do the job for an unsaved new record.

        Thanks,

        Gerry Goldberg

        Comment

        • mseo
          New Member
          • Oct 2009
          • 183

          #5
          ok
          there are two steps to do this :
          1- use beforeupdate trigger on form level to force entering the required field
          and this could be done like this:
          Code:
          Private Sub Form_BeforeUpdate(Cancel As Integer)
              If IsNull(Me![controlname1]) Then
                  MsgBox "field required", vbExclamation
                  Cancel = True: Me![controlname1].SetFocus
             elseif IsNull(Me![controlname2]) Then
                  MsgBox "field required", vbExclamation
                  Cancel = True: Me![controlname2].SetFocus
              End If
          End Sub
          like that you can't save any record without filling the required fields
          then
          on close
          Code:
          Private Sub close_click()
          Dim ER As Integer
           ER = MsgBox("close this form", vbQuestion + vbYesNo)
               If ER = vbYes Then
               Me.Undo
              DoCmd.Close
              End If
          End Sub
          hope this helps

          Comment

          • missinglinq
            Recognized Expert Specialist
            • Nov 2006
            • 3533

            #6
            I'm sorry mseo, but where in the OP's post do you see anything at all about forcing the entry of a required field?

            Posts that aren't germaine to the question at hand seldom do anything other than cloud the issue.

            Linq ;0)>

            Comment

            • mseo
              New Member
              • Oct 2009
              • 183

              #7
              missinglinq
              so, I wouldn't post my solution for this, do you mean that?
              I put the beforeupdate as an addition
              because if we use me.undo on save click the record won't be saved but the user will have the thought that he saved the record, so I would let msgbox fires for him to notify that the record couldn't be saved before filling required fields

              Comment

              • missinglinq
                Recognized Expert Specialist
                • Nov 2006
                • 3533

                #8
                From mseo
                ...I put the beforeupdate as an addition because if we use me.undo on save click the record won't be saved
                Nothing has been said about a "save click" button being used here!

                From mseo
                ...if we use me.undo on save click the record won't be saved but the user will have the thought that he saved the record
                Once again, absolutely nothing has been said by the OP about using a "save" button or forcing required fields to be populated!

                From Gerry Goldberg
                I just want to be able to get rid of a new record that has not been saved. Normally, this occurs if the user accidently creates a new record.
                The OP apparently simply wants a "discard" button to dump an unwanted record when the user realizes that they've added one by mistake.

                While your code sample is valid if the situation requires it, it has nothing to do with the question posted, and only tends, as I said, to confuse things.

                The Answers section of the forum is for just that, posting answers to specific questions!

                We appreciate your participation here, mseo, but tutorials on general subjects, which is what your post amounts to, should only be placed in the Insights section of the forum. Answering unasked questions by adding unneeded information tends to confuse/overload posters who are new to Access and the majority of people coming here for help fall into that category.

                Linq ;0)>

                Comment

                • mseo
                  New Member
                  • Oct 2009
                  • 183

                  #9
                  thanks for pointing out

                  Comment

                  • missinglinq
                    Recognized Expert Specialist
                    • Nov 2006
                    • 3533

                    #10
                    No problem, mseo! Those of us with expertise/proficiency in Access just have to be careful in how we answer a question, so as not to add unnecessary, and sometimes confusing, information for the newbie poster to take in.

                    Linq ;0)>

                    Comment

                    Working...