Access Forms Me.Undo does not honor ctrl-x

huk49

New member
Local time
Today, 23:32
Joined
Jan 16, 2013
Messages
8
Hi Access world

To confess right away: I am an access/VBA beginner.
So here is my challenge: I am testing field entries on a form using the BeforeUpdate event because I hate numerous error messages popping up when I finally want to save the record.
This works fine up to the moment I press the 'Abort' key and want to discard all changes. Using Me.Undo does the trick except when I delete an entry with ctrl-x. It seems Me.Undo does not revoke ctrl-x.

Has anybody have an idea how I can solve my challenge?
Thanks to all and kind regards, huk49 :)
 
Hi Bob

This is to check the required field has an entry:
Private Sub txtDOtitel_BeforeUpdate(Cancel As Integer)
If text_test(Me!txtDOtitel) <> 0 Then
MsgBox "Im Feld 'Titel' muss etwas eingegeben werden!", vbInformation, "RCcompact"
Cancel% = True
End If
End Sub


This is the function used:
Public Function text_test(str_in As Variant) As Long
' given input str_in, return -2 if input is Null,
' -1 if input is zero-length string; otherwise return 0

text_test = IIf(Nz([str_in], "null") = "null", -2, _
IIf(Len(str_in) = 0, -1, 0))
End Function


This code is executed if the Abbrechen (Abort) butten is selected:
Private Sub cmd_Abbrechen_Click()
' reject changes
Me.Undo
' change form
DoCmd.Close acForm, Screen.ActiveForm.Name, acSaveNo
DoCmd.OpenForm "frmDO_mut1", DataMode:=acFormReadOnly
End Sub


Thanks and kind regards, huk49
 
huk49

The code you have used for the Abort button works fine in my version of A2003 and I would expect it work in later versions.
Have you tried using the code in another form, or in another db. I'm clutching at straws really, but I just wondered if you could have a form or database that is becoming corrupt.
 
what happens if you press <escape> after hitting ctrl-x

what you could do, is show recordselectors. with a dirty record, the triangle changes to a pencil. so escape, or undo, cancels pending edits, and the pencil reverts to a triangle.

maybe the ctrl-x is doing somethnig else - like saving the record.
 
Hi Bob and Dave
Thanks for your quick replies.
@Bob
I will build a test db and do some isolated investigations.
@Dave
This is the change sequence:
- Form is displayed with all data inserted.
- I select the title field and cut data out with ctrl-x.
- If I select the abort button the error message (missing data) is displayed.
- If I press ESC the data is filled in again and subsequently pressing the abort button works.
Any ideas what I could do?
I would like to keep the application as simple as possible so that anybody can use it.
Kind regards, hun49
 
@Dave
This is the change sequence:
- Form is displayed with all data inserted.
- I select the title field and cut data out with ctrl-x.
- If I select the abort button the error message (missing data) is displayed.
- If I press ESC the data is filled in again and subsequently pressing the abort button works.

I presume:

ctrl-x removes data from a field. presumably the "title" is declared as a required field, so you cannot save the record with a blank title

esc does a undo, which unwinds the deletion, so you are back to where you started.

now the abort works, but actually does nothing at all.

in actual fact, an abort button is rarely seen - so what does it do, and what is the code for the abort button?



look - show record selectors - then you can see whether the record has been edited or not, and see the effect (in broad terms) of the actions you are taking.
 
Hi Dave
I use the form to update a 'documentation record'. The record contains only three fields: date, title and file-name. All three are required fields. The form also has the following three buttons: a) save any changes made, b) discard any changes made (this is the mentioned abort button) and c) delete the record.
So if the user starts updating the record and on a second thought decides to discard the changes he has started, he can select the 'abort' button to prevent the record being updated. This works fine unless he has deleted one of the entries with ctrl-x.
The record selector solution is fine for technical people like us but I am not sure my everyday users would understand it.
Thanks for your patience and kind regards, huk49
 

Users who are viewing this thread

Back
Top Bottom