cancelling Data Entry

tinyb

New member
Local time
Today, 04:49
Joined
Aug 10, 2006
Messages
6
I have a form that users enter data about suppliers.

What I want to achieve is that when someone presses the CANCEL button that it will discard any data that may have been entered and not send it to the underlying table.

I have considered the setting all fields to a .value = "" but that would delete any data that was in the form that I actually wanted if the cancel was pressed before any new data was entered, say when a user opens the form and then presses cancel or after entering a record and was going to add another record but pressed cancel before doing so.

I was then thinking of the keyacsii value of 27 (esc) but am n ot sure how to implement it.

any help is appreciated

MB
 
If you want undo changes/entries made to a record, whether an existing record or new record, use Me.Undo!

Code:
Private Sub CancelButton_Click()
  Me.Undo
End Sub

Linq
 
@missinglinq

The above code helped me out, for which thank you. I also have the reverse problem and the solution currently escapes me.

On my bound form, used for solely for entering a new record, I have Commit and Cancel buttons. Using VBA, clicking either gives the user an Are You Sure message box. If they give the positive response in either case, the right action happens; the form closes, saving the record or not as appropriate.


However, on giving the negative response, I want them returned to the form in it's original state but it's closing instead.
 
where are you testing for the form close?

if it is somewhere like the unload event (rather than the close event) the header looks like this


Private Sub Form_Unload(Cancel As Integer)

so in here if before end sub you have the command
cancel = vbcancel
(access help will show you that vbcancel is actually value 2, but its best to use the constant)

then access will cancel the form close, and keep the form open.

you get cancel option with some commands (typically before execution - eg before update) and not others (typically after execution - ie after update)

note also that you can achieve undo with

sendkeys "{esc}"

which simulates the action of pressing the escape key
 

Users who are viewing this thread

Back
Top Bottom