Problem with ESC for cancelling new record

spikepl

Eledittingent Beliped
Local time
Today, 23:13
Joined
Nov 3, 2010
Messages
6,142
I have this cancel handler attached to a button on a split form:

Code:
Private Sub cmdFortryd_Click()  ' my cancel button handler
    Me.Undo
    Me.AllowAdditions = False   ' resetting the form
    Me.tglEditKunde.Enabled = True ' showing that we no longer are in edit mode (which we weren't anyway, when canceeling new addition'
    Me.tglEditKunde = False
    Me.tglNyKunde.Enabled = True 'enabling key to add a new customer
    Me.tglNyKunde = False 'settting the value of the "New customer" toggle to false
    Me.DataEntry = False  'setting the form back to normal view
    Me.Refresh ' playng with updates
    Me.Requery 'playing with updates
    Me.Repaint 'playing with updates
    Call SetControls("None") 'resetting various other controls to noneditable status (and shifting foucs form cancel key, to be able to disable it
    Me.cmdFortryd.Enabled = False ' disabling my CANCEL-key
    Me.cmdDone.Enabled = False ' disabling the DONE-key.
End Sub
If I click my button, everything works fine. The button has .Cancel=True.

If I press ESC, then my form goes blank, showing no record. If I try to set focus to some field in a record (in SetControls), Access comes up with : Rutime error 2105 - you cannot go to specified record.

So I put a break-point just before calling SetControls... and when I hit the break-point I just press Continue - and everything works just fine.

So it must have something to do with what is updated and when - but I am sort of stuck.

Any ideas?
 
I have scoured the net and cannot find any similar problem, so my workaround is disabling ESC on the offending form

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyEscape Then
KeyCode = 0
End If

End Sub

If anyone has any ideas please do write.
 
if esc blanks the form, then you probably have a non-updateable record set. Although, I can't quite see in that case how you would ever enter data.
 
I do and I don't - it appears to me it is a question of timing. When I go to the debugger window, focus leaves the offending form, and that apparently is enough for the error to go away. I gave up battling with this, as per my previous post, but it is a bit annoying to disable the ESC key.
 

Users who are viewing this thread

Back
Top Bottom