469,270 Members | 1,002 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,270 developers. It's quick & easy.

How to Undo a new record

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

Thanks,

Gerry Goldberg
Jul 22 '10 #1

✓ answered by missinglinq

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)>

9 34044
missinglinq
3,532 Expert 2GB
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)>
Jul 22 '10 #2
mseo
181 100+
@Gerry Goldberg
you have to provide enough details about your problem to help us provide good solution
undo in mainform or subform?
Jul 22 '10 #3
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
Jul 23 '10 #4
mseo
181 100+
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:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.     If IsNull(Me![controlname1]) Then
  3.         MsgBox "field required", vbExclamation
  4.         Cancel = True: Me![controlname1].SetFocus
  5.    elseif IsNull(Me![controlname2]) Then
  6.         MsgBox "field required", vbExclamation
  7.         Cancel = True: Me![controlname2].SetFocus
  8.     End If
  9. End Sub
like that you can't save any record without filling the required fields
then
on close
Expand|Select|Wrap|Line Numbers
  1. Private Sub close_click()
  2. Dim ER As Integer
  3.  ER = MsgBox("close this form", vbQuestion + vbYesNo)
  4.      If ER = vbYes Then
  5.      Me.Undo
  6.     DoCmd.Close
  7.     End If
  8. End Sub
hope this helps
Jul 23 '10 #5
missinglinq
3,532 Expert 2GB
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)>
Jul 23 '10 #6
mseo
181 100+
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
Jul 23 '10 #7
missinglinq
3,532 Expert 2GB
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)>
Jul 23 '10 #8
mseo
181 100+
thanks for pointing out
Jul 23 '10 #9
missinglinq
3,532 Expert 2GB
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)>
Jul 23 '10 #10

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

18 posts views Thread by Darryl Kerkeslager | last post: by
2 posts views Thread by Leslie | last post: by
4 posts views Thread by Susan Bricker | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.