Problem
VBA code to disable delete key on textbox in MS Access application
Solution
i. Description
This VBA code is used to disable delete key on textbox in MS Access application
ii. Procedure
1. Create a form frmMain
2. Place textbox control on form. Lets say the name of textbox is Text0
3. Select textbox (say Text0), right-click then select properties, select Event tab , On KeyDown, select [Event Procedure] from dropdown, click ... button
Copy & paste the following code under KeyDown event of Text0 textbox
Private Sub Text0_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyDelete Then
MsgBox ("delete key has been disabled")
KeyCode = 0
End If
End Sub
iii.Code
Option Compare Database
Private Sub Text0_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyDelete Then
MsgBox ("delete key has been disabled")
KeyCode = 0
End If
End Sub
iv. Additional Info
This code will disable the delete key on textbox. whenever you click this delete key, it wont work, it just popup a message delete key has been disabled.