delete key

irade92

Registered User.
Local time
Today, 23:39
Joined
Dec 26, 2010
Messages
229
hi
i want to disable the Del key to be pressed in subform.

Thanks
 
If you go into the subform properties and make

Allow Edits = No
Allow Deletions = No

Then you will not be able to change any info in the subform, if that is your intent.
 
If you go into the subform properties and make

Allow Edits = No
Allow Deletions = No

Then you will not be able to change any info in the subform, if that is your intent.

Thanks jkl0 for your effort to answer my quastion..The point is the user must use a command button to delete a record becouse there are still some other comands to do with VBA, but not to delete with Del or Delete key becouse this key is deleteing only current record in a subform
 
I'm not sure if I am answering your question correctly , but, if you turn off your record selector & navigation buttons, the delete key should then only work in a text box for editing the record.

Hope this helps.
 
You could use the code below in the "KeyDown" event of your control:

Code:
Private Sub comboassigned_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 46 Then
       KeyCode = 0
       MsgBox "You cannot delete this value.", vbOKOnly, "Invalid Keystroke"
    Else
        Select Case KeyCode
            Case vbKeyTab, vbKeyReturn, vbKeyDown, vbKeyUp, vbKeyDelete
            'Do nothing
        Case Else
            KeyCode = 0
            MsgBox "You must select a value from the dropdown.", vbOKOnly, "Invalid Input"
        End Select
    End If
End Sub

That will disallow them to use the delete, backspace, and arrow keys while in that control.

You can use KeyCodes for all of the keys if you wish or you can omit the lower half to only disable the delete key while in that control.

Code:
Private Sub comboassigned_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 46 Then
       KeyCode = 0
       MsgBox "You cannot delete this value.", vbOKOnly, "Invalid Keystroke"
   End If
End Sub

Hope this helps.
 
You could use the code below in the "KeyDown" event of your control:

Code:
Private Sub comboassigned_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 46 Then
       KeyCode = 0
       MsgBox "You cannot delete this value.", vbOKOnly, "Invalid Keystroke"
    Else
        Select Case KeyCode
            Case vbKeyTab, vbKeyReturn, vbKeyDown, vbKeyUp, vbKeyDelete
            'Do nothing
        Case Else
            KeyCode = 0
            MsgBox "You must select a value from the dropdown.", vbOKOnly, "Invalid Input"
        End Select
    End If
End Sub

That will disallow them to use the delete, backspace, and arrow keys while in that control.

You can use KeyCodes for all of the keys if you wish or you can omit the lower half to only disable the delete key while in that control.

Code:
Private Sub comboassigned_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 46 Then
       KeyCode = 0
       MsgBox "You cannot delete this value.", vbOKOnly, "Invalid Keystroke"
   End If
End Sub

Hope this helps.

well..it is ok with key preview set yes
Thanks..and have a nice day
 
Last edited:

Users who are viewing this thread

Back
Top Bottom