Rob, that's a very good question so we even made it sticky and changed the topic title from 'Trapping the Enter Key on a Readonly Grid' to 'Trapping the Enter Key in MS Access'.
The problem does not relate to the read-only mode. The problem is in the way Access processes such significant interface keys as ENTER and TAB. MS Access analyzes them first, and only after that we can process them in other form controls - sure, if Access allows us to 'see' them. I mean if a key is an important interface key such ENTER which can affect the whole form (ENTER can be used to move to the next record or next field on the form), Access can simply 'swallow' it. These are two different layers of key processing: the first is the Access form layer, the second is the controls on the form. If the key is processed on the 1st layer, the 2nd won't see it.
You can find a lot of Internet resources explaining how to set the ENTER key behavior in MS Access. In fact, we need the following setting in the Options dialog:
Click to View Image420 View(s)
To solve our problem, first, set the "Move after enter" radio button to the "Don't move" option.
Second, to process ENTER, we need to use the form's KeyDown event. To make it possible, we also need to set the KeyPreview property of the form to True and use code like this:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If Screen.ActiveControl.Name = "iGrid0" Then
If KeyCode = 13 Then
MsgBox "ENTER"
End If
End If
End Sub
Edited by user
2016-11-10T11:48:11Z
|
Reason: Not specified