How to disable undo when the escape key is pressed?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

There is a data entry form where the foreign key field,(required = yes) is
passed to the form via openargs when the form loads.
Once the form is open, if the escape key is pressed, then the this fk field
becomes Null and there is no way to recover the value passed to it with
openargs.
I have tried code on the textbox for this fk field, but nothing stops its
value from being wiped when the escape key is pressed. The form that passes
this value as openargs remains open but hidden, I thought I could code to
pass this value to the textbox for the fk field, but this doesn't work either.
There must be a way to stop this, how?
 
Hi Liz,
The form that passes this value as openargs remains open but hidden, ....
Have you tried reading the value from the hidden form? Something like:

Me.txtBoxName = =[Forms]![frmHiddenFormName]![ControlSourceOfFKField]

Alternatively, you should be able to store the foreign key value in a module level variable as
soon as the form is opened. The example shown below is written for a long integer foreign key :

Option Compare Database
Option Explicit
Dim mlngForeignKey As Long

Private Sub Form_Open(Cancel As Integer)
On Error GoTo ProcError

If Not IsNull(Me.OpenArgs) Then
mlngForeignKey = CLng(Me.OpenArgs)
Else
MsgBox "This form should not be opened by itself. " & vbCrLf & vbCrLf _
& "It should be opened by double-clicking a " & vbCrLf _
& "detail record in the frmContacts subform ", _
vbCritical, "Dialog Form for Comment Entry..."
End If

ExitProc:
Exit Sub

ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, , _
"Error in Form_Open event procedure..."
Resume ExitProc

End Sub


Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.NewRecord Then
Me.fkIndicatorID = mlngForeignKey
End If

End Sub


Tom
_______________________________________


There is a data entry form where the foreign key field,(required = yes) is
passed to the form via openargs when the form loads.
Once the form is open, if the escape key is pressed, then the this fk field
becomes Null and there is no way to recover the value passed to it with
openargs.
I have tried code on the textbox for this fk field, but nothing stops its
value from being wiped when the escape key is pressed. The form that passes
this value as openargs remains open but hidden, I thought I could code to
pass this value to the textbox for the fk field, but this doesn't work either.
There must be a way to stop this, how?
 
: Alternatively, you should be able to store the
foreign key value in a module level variable as
soon as the form is opened. The example shown below is written for a long
integer foreign key :


Thankyou, now I finally understand how to create and use a module level
variable. I assume then that it is not easily possible or possible counter
productive to try to disable the escape key, which by the way is so often
useful.
Thankyou for sharing this with me.
Liz James
 
Hi Liz,

You can disable the escape key if you really want to, but I wouldn't suggest doing so. If a user
backspaces over an entry in a textbox, and then decides to cancel this change by pressing the
escape key, they won't be able to recover the original text if you have disabled the key. Here
is how you would disable it if you want to give it a try:


Set the form's Key Preview property to Yes, and then add this code to the form's module:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 27 'Escape key
KeyCode = 0
End Select
End Sub

I'm simply using an idea very similar to that shown here:
http://support.microsoft.com/?id=208826

I used a debug.print statement in this procedure to learn the appropriate KeyCode (ie. 27) for
the escape key.

Tom
_____________________________________

: Alternatively, you should be able to store the
foreign key value in a module level variable as
soon as the form is opened. The example shown below is written for a long
integer foreign key :


Thankyou, now I finally understand how to create and use a module level
variable. I assume then that it is not easily possible or possible counter
productive to try to disable the escape key, which by the way is so often
useful.
Thankyou for sharing this with me.
Liz James
 
Hi Liz,

You're very welcome.

Tom
________________________________


Tom, thankyou very much. I appreciate your time and effort.
 
Back
Top