Henry_Harris
asked on
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
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
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.
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.
ASKER
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
My solution that works, made use of Form.Undo rather than Control.Undo.
Would you guys mind sharing the points.
<<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.
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.
ASKER
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.
Thanks both.
The other thought would be to look at a more robust solution like SQL 200x Express and VB.Net
If Me.Dirty Then
Me.Undo
End If
This would be done in the Before Update event.