Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Rob  
#1 Posted : Tuesday, October 16, 2012 5:29:40 PM(UTC)
Rob

Rank: Newbie

Groups: Registered
Joined: 10/12/2012(UTC)
Posts: 8
Location: Cleveland, OH

I am using the latest version of iGrid in MS Access 2007. I have setup the grid so that it is a large, read-only (.Editable = False) list that a user will select a row from (.RowMode = True). A detail form will be called whenever a user either double-clicks (which I have working) or hits the "enter" key (which is not working).

How do I capture the Enter key, keep the focus on the grid, and not let it go into cell edit mode?

-- Rob

Edited by moderator Monday, February 25, 2013 12:03:09 PM(UTC)  | Reason: Not specified

Igor/10Tec  
#2 Posted : Wednesday, October 17, 2012 7:54:23 AM(UTC)
Igor/10Tec

Rank: Administration

Groups: Administrators, Forum Moderator
Joined: 1/17/2011(UTC)
Posts: 1,114

Thanks: 15 times
Was thanked: 141 time(s) in 141 post(s)
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:

MS Access Enter Key Behavior Setting.png

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:

Code:
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 Thursday, November 10, 2016 11:48:11 AM(UTC)  | Reason: Not specified

Rob  
#3 Posted : Wednesday, October 17, 2012 6:55:13 PM(UTC)
Rob

Rank: Newbie

Groups: Registered
Joined: 10/12/2012(UTC)
Posts: 8
Location: Cleveland, OH

Igor, as your mentioned, there is an Advance Option in MS Access that allows you to specify what what happens when you hit the ENTER key - Don't move, Next Field and Next Record. The downside to this is that it is a universal setting and applies to all databases and forms. I came across a post on the internet with another suggestion that seems to work.

1. On the Form, set Key Preview to True
2. Capture the Keystroke using the "On Key Down" event of the form
3. Change the value of KeyCode to whatever value represents the key you would like the system to process. In my case, I want the system to do nothing, so I set the value of KeyCode to -1.

So the code looks like this:

Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If Screen.ActiveControl.Name = "ilstList" Then
        If KeyCode = 13 Then
            MsgBox "ENTER"
            KeyCode = -1  'changes the KeyCode to a value ignored by the system
        End If
    End If
   
End Sub

Edited by moderator Monday, February 25, 2013 12:02:50 PM(UTC)  | Reason: Not specified

Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.