access 2003 and function key trapping

  • Thread starter Thread starter madhouse
  • Start date Start date
M

madhouse

Hi
access 2003 form.
trying to trap all key presses especially function keys.
have msgbox in Form_KeyUp event displaying keycode.
this gets hit with esc, enter, all function keys except
f1,f5,f6,f12. these appear to always do built-in
processes provided by access.
is there any way to trap these and override those built
in processes?
Any advice would be greatly appreciated, thanks
 
Hello,

The example below will display a message box saying Hello instead of viewing
help when the F1 key is pressed

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

' See if the F1 key was pressed
If KeyCode = vbKeyF1 Then
' Display a message box
MsgBox "Hello"
' Reset the keycode so that help isnt displayed
KeyCode = 0
End If

End Sub

Note that KeyPreview has to be set to Yes (in the forms properties) for the
forms keydown event to fire.

I would however try to avoid overridding the default buttons as this could
confuse your users if they are use to using Access. Try and use key
combinations which are rearly used (i am sure there is a list of all
keyboard shortcuts somewhere that Access uses).

HTH,

Neil.
 
-----Original Message-----
Hello,

The example below will display a message box saying Hello instead of viewing
help when the F1 key is pressed

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

' See if the F1 key was pressed
If KeyCode = vbKeyF1 Then
' Display a message box
MsgBox "Hello"
' Reset the keycode so that help isnt displayed
KeyCode = 0
End If

End Sub

Note that KeyPreview has to be set to Yes (in the forms properties) for the
forms keydown event to fire.

I would however try to avoid overridding the default buttons as this could
confuse your users if they are use to using Access. Try and use key
combinations which are rearly used (i am sure there is a list of all
keyboard shortcuts somewhere that Access uses).

HTH,

Neil.




.
Thanks Neil, that's great, I was using the keyup event.
Do you know if there's anyway to detect if the form is
in "filter by form" mode and when in this mode to
intercept keypresses?
 
Hi,

There are 2 events which may come in usefull here. The On Filter and On
Apply Filter.

The On Filter event fires when the user goes into Filter mode. In this
event, you could set a global variable to indicate that a filter has been
set. The Apply Filter event fires when you apply a filter. In here you could
set your glabal variable to indicate that the filter has been applied.

The 2 events also have arguments - FilterType for On Filter and ApplyType
for On Apply Filter. Using both of these arguments together will indicate
what filter view the user went into (filter by form or advanced) and if a
filter was applied. Look in the help files for more info on how to use
these. Anyway an example is as follows:

--------------------------

' Global Variable in General Declarations section
Dim blnInFilterByForm As Boolean

Private Sub Form_ApplyFilter(Cancel As Integer, ApplyType As Integer)

' Set global variable to indicate that a filter has been applied/removed
' Either way, the form is no longer in Filter-By-Form Mode
blnInFilterByForm = False

End Sub

Private Sub Form_Filter(Cancel As Integer, FilterType As Integer)

' Check to see which filter view the user has gone to
If FilterType = acFilterByForm Then
' Set the global variable to indicate that the user is viewing the
form in Filter-By-Form mode
blnInFilterByForm = True
End If

End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

' See if the F1 key was pressed
If KeyCode = vbKeyF1 Then
' Check to see if in Filter-by-Form mode
If blnInFilterByForm Then
' Display a message box
MsgBox "Pressing F1 Key while in Filter-by-Form mode."
End If
' Reset the keycode so that help isnt displayed
KeyCode = 0
End If

End Sub

--------------------------

I havnt tested the code avbove so i hope it works ok.

Good luck!

Neil.
 
-----Original Message-----
Hi,

There are 2 events which may come in usefull here. The On Filter and On
Apply Filter.

The On Filter event fires when the user goes into Filter mode. In this
event, you could set a global variable to indicate that a filter has been
set. The Apply Filter event fires when you apply a filter. In here you could
set your glabal variable to indicate that the filter has been applied.

The 2 events also have arguments - FilterType for On Filter and ApplyType
for On Apply Filter. Using both of these arguments together will indicate
what filter view the user went into (filter by form or advanced) and if a
filter was applied. Look in the help files for more info on how to use
these. Anyway an example is as follows:

--------------------------

' Global Variable in General Declarations section
Dim blnInFilterByForm As Boolean

Private Sub Form_ApplyFilter(Cancel As Integer, ApplyType As Integer)

' Set global variable to indicate that a filter has been applied/removed
' Either way, the form is no longer in Filter-By- Form Mode
blnInFilterByForm = False

End Sub

Private Sub Form_Filter(Cancel As Integer, FilterType As Integer)

' Check to see which filter view the user has gone to
If FilterType = acFilterByForm Then
' Set the global variable to indicate that the user is viewing the
form in Filter-By-Form mode
blnInFilterByForm = True
End If

End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

' See if the F1 key was pressed
If KeyCode = vbKeyF1 Then
' Check to see if in Filter-by-Form mode
If blnInFilterByForm Then
' Display a message box
MsgBox "Pressing F1 Key while in Filter-by- Form mode."
End If
' Reset the keycode so that help isnt displayed
KeyCode = 0
End If

End Sub

--------------------------

I havnt tested the code avbove so i hope it works ok.

Good luck!

Neil.



.
Thanks Neil, that all makes a lot of sense, i can
certainly see what you're doing. However the remaining
problem seems to be that my keydown event is not hit when
pressing the fn keys while editing a cell in filter by
form mode. I must be missing something...
 
Thats interesting. You learn something new everday. The Key down event
doesnt fire when in filter mode. I would suggest re-posting to the newsgroup
and axplain what you are trying to do. Maybe then, someone could give you an
alternative way of acheiving the same thing.

Sorry I couldn't help.

Neil.
 
-----Original Message-----
Thats interesting. You learn something new everday. The Key down event
doesnt fire when in filter mode. I would suggest re- posting to the newsgroup
and axplain what you are trying to do. Maybe then, someone could give you an
alternative way of acheiving the same thing.

Sorry I couldn't help.

Neil.



.
Thanks Neil, I'll do as you suggest,
 
Back
Top