Abandon Edit

C

Carriolan Shinobi

Hi I hope some one can help me out with this. I have set up a memo
field on a form and opened it as edit. If I want to abandon all edits
without saving I can press the Esc key. However I want to attach it to
a command button as an OnClick Event, but Sendkeys {ESC} does not work
in my macro. Any ideas?

Regards
 
B

Brendan Reynolds

In order to click on a button, the focus must move away from the text box,
which means that the value of the text box must be updated before you can
click the button. The result is that you will not be able to cancel only the
changes to that specific control using a button, you will have to cancel all
changes made to the contents of any controls on the form since the last time
the record was saved. You can do that using the Undo method of the form ...

Private Sub Command10_Click()

'This would undo only changes to the contents
'of this control, but it won't work from a command
'button click event.
Me.Controls("TestMemo").Undo

'This will undo all changes to the contents
'of any controls since the last time the record
'was saved.
Me.Undo

End Sub
 
M

Marshall Barton

Carriolan said:
Hi I hope some one can help me out with this. I have set up a memo
field on a form and opened it as edit. If I want to abandon all edits
without saving I can press the Esc key. However I want to attach it to
a command button as an OnClick Event, but Sendkeys {ESC} does not work
in my macro. Any ideas?


Not the same as usng the Esc key, but you can reset the memo
text box to it's value at the last time it was saved by
setting it to its OldValue property:

Me.txtmemo = me.txtmemo_OldValue
 
C

Carriolan Shinobi

Hi Brendan
Because I am using Ctrl + Enter to generate a new line in the memo
field, the Undo method only reverses out all amendments since the last
Ctrl + Enter. Hence I am trying to get the Esc key to work in a macro
as it works directly from the key.
Rgds Carriolan.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top