Undo Upon Exit

Earl C Phillips

Volunteer Programmer
Local time
Yesterday, 21:30
Joined
Jul 18, 2008
Messages
40
I was getting inconsistent results using Me.Undo to prevent updating a record except when intended using the "Add Record" button. I corrected that based upon the responce I received which stated that Me.Undo needed to be in an event that was cancelable.

I inserted a public flag, set the flag as true when pressing a "Return to Main" button, and wrote:
if flag = true then
me.undo
cancel = true
flag = false
goto Exit_cancelablesub_BeforeUpdate
end if

I also wrote:
Private Sub Form_KeyPress(KeyAscii As Integer)
If (KeyAscii=vbKeyReturn) Or (KeyAscii = vbKeyF5) Or _
(keyAscii = vbkeyF9) Then
KeyAscii = 0
End If
Exit_Form_KeyPress:
Exit Sub

It still creates a record when I press F5 or F9. Why?
 
Last edited:
There was an error in the prior posting. I would set the Public Flag to true and call the cancelable subroutine from the Return_To_Main subroutine:

Flag = True
cancelable_BeforeUpdate (1)

In the cancelable subroutine I wrote:
if flag = true then
me.undo
cancel = true
flag = false
goto Exit_cancelablesub_BeforeUpdate
end if

I also wrote a separate subroutine to try to control the F5 & F9 keys:
Private Sub Form_KeyPress(KeyAscii As Integer)
If (KeyAscii=vbKeyReturn) Or (KeyAscii = vbKeyF5) Or _
(keyAscii = vbkeyF9) Then
KeyAscii = 0
End If
Exit_Form_KeyPress:
Exit Sub

The F5 clears the screen and writes to the table. The F9 key just writes to the table.

Why can't I prevent the F5 and F9 from writing to the table?:confused:
 

Users who are viewing this thread

Back
Top Bottom