Disable Delete key

R

rmcompute

I created an employee form which allows the user to delete the employee by
hitting a command button. The code behind the command button then deletes
the employee as well as all of the supporting tables.

How can I prevent the user from deleting the record with the delete key, so
the system is forced to delete the supporting tables ?
 
G

Gina Whipp

I don't get it... You might want to clarify your question... Sounds like
you want the delete key just to get rid of the tables??? not sure why you
would want the tables deleted, perhaps you meant record???

AND say how your tables are set up, sounds like they support cascading
deletes but can't be sure if you even have it enforced.

HTH,
Gina Whipp
 
R

rmcompute

I don't want the user to be able to put the cursor on the record of the form
and press the delete key on the keyboard of the computer. When this
happens, the record is deleted from the current table. I set up a command
button on the form which I want the user to use to delete a record. When
that key is pressed, the record is deleted from the current table, but also
there is code behind the command button which deletes various records in
other tables and performs other clean-up processes. Since there is no way to
prevent the user from pressing the delete key on the computer, do you know
how to determine if it was pressed and perhaps display an error message and
prevent the user from deleting the record in this way ?
 
A

AccessVandal via AccessMonster.com

First, is the form a continuous or single? And is the form’s property “Record
Selectors†= Yes?

If “Record Selectors†is No, the user can only edit data. The “Delete†or
“Del†key is only use for edit in this case.

If Yes, you’ll need the “Form_KeyDown Event†to reset the keys.

Depending on the type of keyboard, you’ll need to determine which key can
delete the record.

‘use this in the keydown event of your form
‘use debug to check the number, delete after using
Debug.Print KeyCode ‘ use to check the KeyCode number
‘US keyboard 101 type
Select Case KeyCode
Case 46 ‘Delete Key number, “Del†is 110
‘MsgBox “Your message here if neededâ€
‘reset keycode
KeyCode = 0
End Select
 
T

tedmi

Set the form's AllowDelete property to 0 (False)
In the GUI, you'll find this on the Data tab of the properties window.
 
G

Gina Whipp

I don't believe that will work because when you want to delete a record you
can't. AccessVandal has the best solution so far.

Gina Whipp
 
R

rmcompute

I agree; AccessVandal's solution worked.

Gina Whipp said:
I don't believe that will work because when you want to delete a record you
can't. AccessVandal has the best solution so far.

Gina Whipp
 
T

TedMi

Don't forget, however, that if Num Lock is off, there are TWO delete keys on
the keyboard. And will it work on every laptop keyboard? And what if the user
clicks the delete button on the toolbar?
Deletes will always work, regardless of AllowDeletions property, if executed
with a Delete query, rather than the DoCmd code produced by the Command
Button delete wizard. But if you insist on the wizard code, wrap it in code
that sets then resets the AllowDeletions property:

Private Sub ButtonName_Click
Me.AllowDeletions = True
' do the deletes and cleanup here
Me.AllowDeletions = False
End Sub
 
A

AccessVandal via AccessMonster.com

No point creating a button.
Just set the form's property Data tab - "Allow Deletions" = No.

That will depends on how he'll design the database.

Menus and toolbars can be disable. Even the Querys and
VBA Editor can be remove.

You can use the security to lock the table and records form
deletion.
Don't forget, however, that if Num Lock is off, there are TWO delete keys on
the keyboard. And will it work on every laptop keyboard? And what if the user
clicks the delete button on the toolbar?
Deletes will always work, regardless of AllowDeletions property, if executed
with a Delete query, rather than the DoCmd code produced by the Command
Button delete wizard. But if you insist on the wizard code, wrap it in code
that sets then resets the AllowDeletions property:

Private Sub ButtonName_Click
Me.AllowDeletions = True
' do the deletes and cleanup here
Me.AllowDeletions = False
End Sub
I agree; AccessVandal's solution worked.
[quoted text clipped - 7 lines]
 
Top