473,394 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

I get three different behaviors using undo. Help?!

In the data entry area of my access application, I give users an opportunity to undo. The same code gives me three different behaviors.

When I first test it, it works fine. But if I edit the field again and click elsewhere, I get an error that "the command or action undo isn't available". And if I cancel the error message dialog box and edit the field again, click elsewhere. This time the undo deletes the entire edited field.

Please help.

All of the data and the code are in a subform:

Private Sub Form_AfterUpdate()
Dim intYesNo As Integer
intYesNo = MsgBox("Yes to Save, No to Delete Record", vbQuestion + vbYesNoCancel, "Enter")
If intYesNo = vbYes Then
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
ElseIf intYesNo = vbNo Then

'when it crashes, the debugger brings me to this line
DoCmd.RunCommand acCmdUndo
End If
End Sub

In a different iteration, I tried Me.undo in the subform, instead of acCmdUndo. When I test it in the subform as a free-standing form it works fine. But when I test it in the subform as part of the "master form" it does NOTHING.
Nov 3 '08 #1
7 1709
puppydogbuddy
1,923 Expert 1GB
Try changing the event proc:

From this: Private Sub Form_AfterUpdate()

To this: Private Sub Form_BeforeUpdate()

AfterUpdate is after changes have been saved, and you can't undo after the change has been saved.
Nov 3 '08 #2
Try changing the event proc:

From this: Private Sub Form_AfterUpdate()

To this: Private Sub Form_BeforeUpdate()

AfterUpdate is after changes have been saved, and you can't undo after the change has been saved.

Thanks Puppydog, but that can't be it; the undo DOES work once.

And I tried changing to afterupdate and I got an error message that my code was preventing Access from saving data in the field.

Any other ideas?
Nov 3 '08 #3
missinglinq
3,532 Expert 2GB
PuppyDogBuddy is correct in saying that this type of code needs to be in the BeforeUpdate event, but that also makes some of your code inappropriate. You don't need the line to save the record, Access will do that automatically if you don't cancel the update. You also want to use vbYesNo, not vbYesNoCance in your messageboxl. You only have two choices here, save or don't save the record. This code should get the job done

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.  Dim intYesNo As Integer
  3. intYesNo = MsgBox("Yes to Save, No to Delete Record", vbQuestion + vbYesNo, "Enter")
  4. If intYesNo = vbNo Then
  5. DoCmd.RunCommand acCmdUndo
  6. Cancel = True
  7. End If
  8. End Sub
Welcome to Bytes!

Linq ;0)>
Nov 3 '08 #4
puppydogbuddy
1,923 Expert 1GB
Thanks Linq,
I forgot to change the code to take out the save.

pDog
Nov 3 '08 #5
missinglinq
3,532 Expert 2GB
Four eyes always be better than two!

;0)>
Nov 3 '08 #6
Thank you Missinglinq. It worked -- I don't understand why, but it worked.


PuppyDogBuddy is correct in saying that this type of code needs to be in the BeforeUpdate event, but that also makes some of your code inappropriate. You don't need the line to save the record, Access will do that automatically if you don't cancel the update. You also want to use vbYesNo, not vbYesNoCance in your messageboxl. You only have two choices here, save or don't save the record. This code should get the job done

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.  Dim intYesNo As Integer
  3. intYesNo = MsgBox("Yes to Save, No to Delete Record", vbQuestion + vbYesNo, "Enter")
  4. If intYesNo = vbNo Then
  5. DoCmd.RunCommand acCmdUndo
  6. Cancel = True
  7. End If
  8. End Sub
Welcome to Bytes!

Linq ;0)>
Nov 3 '08 #7
missinglinq
3,532 Expert 2GB
Glad we finally got it working for you!

Linq ;0)>
Nov 3 '08 #8

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

Similar topics

3
by: Enigman O'Maly | last post by:
I've written, er, that is, recorded and re-written a lot of little useful macros to help me with a spreadsheet dealing with financial investments. Very handy they are, yes, but sometimes I wish I...
137
by: Philippe C. Martin | last post by:
I apologize in advance for launching this post but I might get enlightment somehow (PS: I am _very_ agnostic ;-). - 1) I do not consider my intelligence/education above average - 2) I am very...
18
by: Darryl Kerkeslager | last post by:
I don't do much with subforms - in fact I've deliberately avoided them - but .... I have a tab control that will contain several subforms, each bound to a separate table, and each table/subform...
3
by: babylon | last post by:
any facilities in csharp that can help me implmenting undo/redo in my application? thx
11
by: Mad Joe | last post by:
I'm using a richTextBox for editing a source code (with Syntax Highlighting) of my own programming language... How come that myRichTextBox doesn't respond to Undo/Redo functions by using default...
3
by: bobchabot | last post by:
I have a db I am working on that contains three fields: Name, Time, Date. I want to make Access bring up a warning box that tells the user when they have a conflict.... meaning scheduling the same...
1
by: aaronkm | last post by:
Hello thescripts!, I hope this is easy for someone to answer, I just can't seem to figure it out. On my main form, within a Tab Control I have a ComboBox named: GapArea that is filtered by...
1
by: dantebothermy | last post by:
The application I'm developing allows the user to edit fields. If a field has changed when the user clicks on a different control (or another record in the multi-record subform), a messagebox gives...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.