Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

over-ride default arrow key form navigation behaviour

Avatar of AltaSens
AltaSensFlag for United States of America asked on
Microsoft Access
8 Comments1 Solution593 ViewsLast Modified:
I am using the code listed below to allow users to navigate between controls in a form which is layed out in a grid (sort of like Excel) using the arrow keys.  This works except for when the current focus is at the edge of the grid (i.e. top/bottom row, leftmost/rightmost column) of controls then the default arrow key behaviour takes over the up/left keys goto the previous control in the taborder, right/down goto the next control.

Is there any way to over-ride this default key navigation behaviour?

THANKS!


__________________________
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If Screen.ActiveControl.Name Like "#-#" Or Screen.ActiveControl.Name Like "#-##" Then

        intColNumber = Left(CStr(Screen.ActiveControl.Name), 1)
        intRowNumber = Mid(CStr(Screen.ActiveControl.Name), 3, Len(CStr(Screen.ActiveControl.Name)) - 2)
       
        Select Case KeyCode

            Case vbKeyDown
                If intRowNumber < intNumRows Then
                    strFormFieldName = CStr(intColNumber) & "-" & CStr(intRowNumber + 1)
                    Forms!TimeEntry(strFormFieldName).SetFocus
                Else
                    Screen.PreviousControl.SetFocus
                End If
         
            Case vbKeyUp
                If intRowNumber > 1 Then
                    strFormFieldName = CStr(intColNumber) & "-" & CStr(intRowNumber - 1)
                    Forms!TimeEntry(strFormFieldName).SetFocus
                Else
                    Screen.PreviousControl.SetFocus
                End If
       
            Case vbKeyLeft
                If intColNumber > 1 Then
                    strFormFieldName = CStr(intColNumber - 1) & "-" & CStr(intRowNumber)
                    Forms!TimeEntry(strFormFieldName).SetFocus
                Else
                    Screen.PreviousControl.SetFocus
                End If
       
            Case vbKeyRight
                If intColNumber < 7 Then
                    strFormFieldName = CStr(intColNumber + 1) & "-" & CStr(intRowNumber)
                    Forms!TimeEntry(strFormFieldName).SetFocus
                Else
                    Screen.PreviousControl.SetFocus
                End If

        End Select

    End If
 
End Sub
__________________________

ASKER CERTIFIED SOLUTION
Avatar of harfang
harfangFlag of Switzerland image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 8 Comments.
See Answers