Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 686
  • Last Modified:

Undoing a record

I am building a database that I need to make as robust and "idiot-proof" as possible. For the latter, this means that every eventuality has to have a user friendly outcome to a non-computer person.
This case involves undoing a record that is partially entered by the user. In particular, when a field is keyed but the user decides to clear it by backspacing and then clicking away from the record, I need that record not to be saved in the table.
I have included a sample database and a Word document with a few illustrations. The database has some code for "Before Update" for the Form and for the Field.
Firstly, is what I want to do possible? Secondly my code produces unexpected messages when in tracing mode, but different ones when there are no breakpoints.
Please assist.
Thanks in anticipation.
Undo.zip
0
Henry_Harris
Asked:
Henry_Harris
2 Solutions
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
This will undo the record:

If Me.Dirty Then
  Me.Undo
End If

This would be done in the Before Update event.

0
 
peter57rCommented:
You will have to define 'partially entered'  and convert that into code which tests specific fields for data values as a record is about to be saved.

So in the form_beforeupdate event procedure you might have..

if isnull(me.field1) or isnull(me.field2) then
 if msgbox( "incomplete record. Do you want to Save?", vbQuestion+vbyesno) = vbno then
    me.undo  ' will undo all entries made so far
    cancel = true ' cancels save
  else ' allow save to proceed
   ' do nothing
  end if
else  ' all fields are ok
' do nothing
end if

You need to bear in mind that this will undo all entries/changes if a No response is given.


0
 
Henry_HarrisAuthor Commented:
Thanks for your posts.
I simplified my sample, but it looks as though I oversimplyfied it. Please find attached a more appropriate sample.
Having been prompted by your replies, I have looked even harder at what I have been trying to achieve. The sample I have attached still has a problem when an entry is started in the subform, backspaced clear and then clicked away.
I believe I know the solution, but I would welcome opinions from others.
Undo.zip
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
<<The sample I have attached still has a problem when an entry is started in the subform, backspaced clear and then clicked away.
I believe I know the solution, but I would welcome opinions from others.>>
  When it comes to subforms, you have two options:
1. Bind the main and subform in code so you can use a transaction
2. use temp tables - when the user edits or adds, you copy everything to the temp tables.  If they save, you copy back.  If they cancel, you simply don't do anything.
  The problem with a main/subform combination is that Access comits the main form record when you enter a subform (you don't even have to do anything to it).
JimD.
0
 
Helen FeddemaCommented:
I agree with Jim.  For total control of backing out of creating a new record, make your form(s) unbound, and only save the new record (perhaps with a confirmation) when the user clicks a Save button.
0
 
Henry_HarrisAuthor Commented:
Thank you for your posts. It looks as though I have to learn more about Access, especially the term transactions. Your advice is welcome, it is just a bit more than I am used to.
My solution that works, made use of Form.Undo rather than Control.Undo.
Would you guys mind sharing the points.
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
<<Thank you for your posts. It looks as though I have to learn more about Access, especially the term transactions. Your advice is welcome, it is just a bit more than I am used to.>>
Yes, unfortunately this is one area I think Access is quite poor. I understand the reasons behind it and why it is the way it is, but you would think they (Microsoft) would have done it differently.
<<Would you guys mind sharing the points.>>
No issues with that. Helen's idea of an unbound main form is a good one!
JimD.
0
 
Henry_HarrisAuthor Commented:
Good responses. I have only marked it partially easy to follow as the recommendations, which I accept, require me to do some extra learning.
Thanks both.
0
 
Jim P.Commented:
The other thought would be to look at a more robust solution like SQL 200x Express and VB.Net
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now