Disable Keys

alpapak

Registered User.
Local time
Today, 01:39
Joined
Apr 3, 2006
Messages
64
hi
i want to make a module which it will run when my db start and it will disable some keys . I want to disble them as long my db is open.

i read some post and found
code:
Select Case KeyCode
Case vbKeyF1
KeyCode = ""
Case vbKeyF2
KeyCode = ""
Case vbKeyF11
KeyCode = ""
Case Else
End Select

i know that i will make a module and call it from my splash screen or startup.
i don't know the code??? and how to make it work as long my db is open.

thxs in advance
 
Oldsoftboss is correct; you cannot call code from a splash screen or startup to accomplish this. You have to do this for each and every form in your database that you want affected. Also your code KeyCode = "" won't work, as Access expects either an integer or a VB constant.

To accomplish your goal you need to do the following:

1) In the Form's Property Box set KeyPreview to TRUE:

2) Set the KeyCode for the keys you want to co-op to zero in the Form_Keydown event:

Code:
Private Sub form_keydown(KeyCode As Integer, Shift As Integer)

  Select Case KeyCode
    Case vbKeyF1
      KeyCode = 0
    Case vbKeyF2
      KeyCode = 0
    Case vbKeyF11
      KeyCode = 0
    Case Else
  End Select

End Sub

Be aware that in setting the F1 KeyCode to zero you're disabling Access' native Help feature!
 
what will happen in you have a text box that user has to fill in, would the form-keydown event allways come on?
 
Yes, but what's your point/question? The keydown event happens whenever a key is pressed.
 
so if i have a text field that is 254 bytes long, and a user type in a senetence that is 254 bytes long , so eacg type a key is pressed, the event will come on
 
If KeyPreview is set to TRUE the event will be checked each time a key is pressed.
 
I am using Access 2003. I used the following code on Key Down event of the form and set the KeyPreview to Yes.

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

Select Case KeyCode
Case vbKeyF12
KeyCode = 0
Case Else
End Select

End Sub
On hitting F12, I still get the pop up window. Any solution?
 
I popped your code into a test db I had at hand and it works as it's supposed to. You might double cjheck the KeyPreview property settings. I've made changes and found later that they didn't "take."
 

Users who are viewing this thread

Back
Top Bottom