Article ID: 113547
Article Last Modified on 1/18/2007
Private Sub Text2_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
' If user presses TAB, ENTER, PAGE UP, PAGE DOWN
Case 13, 9, 33, 34
' Disable the keystroke by setting it to 0
KeyCode = 0
Case Else
Debug.Print KeyCode, Shift
End Select
End Sub
NOTE: In Microsoft Access 7.0 and Microsoft Access 97 controlling the tab
order is much easier.
Option Explicit
Global Const VK_CONTROL = &H11
Global Const VK_SHIFT = &H10
Global Const VK_TAB = &H9
Global Const VK_RETURN = &HD
Global Const VK_PRIOR = &H21 ' PGUP
Global Const VK_NEXT = &H22 ' PGDN
Declare Function GetKeyState% Lib "user.exe" (ByVal nKey%)
Function CheckKey ()
Dim sControl As String
Dim sShift As String
' Was the CTRL or SHIFT key used?
If GetKeyState(VK_CONTROL) < 0 Then sControl = "Ctrl+"
If GetKeyState(VK_SHIFT) < 0 Then sShift = "Shift+"
' Was the TAB key used?
If GetKeyState(VK_TAB) < 0 Then
MsgBox "You pressed " & sControl & sShift & "TAB!"
End If
' Was the ENTER or RETURN key used?
If GetKeyState(VK_RETURN) < 0 Then
MsgBox "You pressed " & sControl & sShift & "ENTER!"
End If
' Was the PAGE DOWN key used?
If GetKeyState(VK_NEXT) < 0 Then
MsgBox "You pressed " & sControl & sShift & "PGDN!"
End If
' Was the PAGE UP key used?
If GetKeyState(VK_PRIOR) < 0 Then
MsgBox "You pressed " & sControl & sShift & "PGUP!"
End If
End Function
=CheckKey()
Option Explicit
Global Const VK_RETURN = &HD
Declare Function GetKeyState% Lib "user.exe" (ByVal nKey%)
Function MakeEnterAddLines()
If GetKeyState(VK_RETURN) < 0 Then
DoCmd CancelEvent
SendKeys "^{ENTER}"
End If
End Function=MakeEnterAddLines()
Option Explicit
Global Const VK_PRIOR = &H21 ' PGUP
Global Const VK_NEXT = &H22 ' PGDN
Declare Function GetKeyState% Lib "user.exe" (ByVal nKey%)
Function DisablePGUP_PGDN()
If GetKeyState(VK_PRIOR) < 0 Or GetKeyState(VK_NEXT) < 0 Then
DoCmd CancelEvent
End If
End Function=DisablePGUP_PGDN()
Option Explicit
Global Const VK_TAB = &H9
Global Const VK_SHIFT = &H10
Declare Function GetKeyState% Lib "user.exe" (ByVal nKey%)
Function TABtoMainForm(F As Form)
Dim DS As Dynaset
On Error Goto Bye_TABtoMainForm
' Move to last record in form dynaset.
Set DS = F.Dynaset
DS.MoveLast
' See if the form record is the last record.
If DS.Bookmark = F.Bookmark Then
If GetKeyState(VK_TAB) < 0 And Not _
(GetKeyState(VK_SHIFT) < 0) Then
DoCmd CancelEvent
SendKeys "^{TAB}"
End If
End If
Bye_TABtoMainForm:
End Function
=TABtoMainForm(Form)
Additional query words: trapping
Keywords: kbhowto kbprogramming kbusage KB113547