By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,489 Members | 1,954 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,489 IT Pros & Developers. It's quick & easy.

how to disable function keys in access 2010

P: 62
I want to disable function keys in access 2010,for that i am using code on forms on key down event.
Code is
Expand|Select|Wrap|Line Numbers
  1. 'The forms Key Preview property must be set to Yes
  2. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  3.  
  4.     Select Case KeyCode
  5.         Case vbKeyDelete
  6.             MsgBox "The Delete key was Pressed"
  7.             KeyCode = 0
  8.         Case vbKeyF1
  9.             MsgBox "The F1 key was Pressed"
  10.             KeyCode = 0
  11.         Case vbKeyF2
  12.             MsgBox "The F2 key was Pressed"
  13.             KeyCode = 0
  14.         Case Else
  15.             'MsgBox "No match!" 'testing
  16.     End Select
  17.  
  18. End Sub
  19.  
This works well but i want to create module and that module will be called in startup form and it will be applicable to call forms and reports.
Is it possible
Thank you in advance
Jan 10 '14 #1

✓ answered by NeoPa

I would suggest a slight modification.

TrapFunction() should, indeed, be a function procedure, rather than a subroutine procedure as shown.

The call to it should assign KeyCode to the result.
Expand|Select|Wrap|Line Numbers
  1. Public Function TrapFunction(KeyCode As Integer) As Integer
  2.     'blah di blah
  3.     TrapFunction = {whatever}
  4. End Function
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) 
  2.     KeyCode = TrapFunction(KeyCOde)
  3. End Sub
The rest of the post (#2) is well worth checking out too, as it deals with a very powerful technique to help secure your databases.

Share this Question
Share on Google+
3 Replies


zmbd
Expert Mod 5K+
P: 5,287
Create the procedure in a standard code module using parameter, for example
Expand|Select|Wrap|Line Numbers
  1. sub trapfunction(byval keydown as Integer)
  2. 'remaining code omitted (^_^)
Then for each form where you want to trap the function keys in the Keydown event, call the procedure
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) 
  2. Call trapfunction(KeyCOde)
  3. End Sub 
There is also the AutoKeys macro... it is one of the only special case macros I use as I trap the [F1] and [F11] keys using this macro, even if the bypass key is used, the AutoKeys macro usually works.... be very careful using this macro as you can lock yourself out of things you need.
Jan 10 '14 #2

NeoPa
Expert Mod 15k+
P: 31,186
I would suggest a slight modification.

TrapFunction() should, indeed, be a function procedure, rather than a subroutine procedure as shown.

The call to it should assign KeyCode to the result.
Expand|Select|Wrap|Line Numbers
  1. Public Function TrapFunction(KeyCode As Integer) As Integer
  2.     'blah di blah
  3.     TrapFunction = {whatever}
  4. End Function
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) 
  2.     KeyCode = TrapFunction(KeyCOde)
  3. End Sub
The rest of the post (#2) is well worth checking out too, as it deals with a very powerful technique to help secure your databases.
Jan 10 '14 #3

zmbd
Expert Mod 5K+
P: 5,287
after reading Neopa's suggestion, the function certainly makes more sense. I was only thinking about trapping the key, and not what to do withit afterwards.
Jan 10 '14 #4

Post your reply

Sign in to post your reply or Sign up for a free account.