PDA

View Full Version : Disable Ctrl key actions



lifeson
08-23-2007, 11:37 PM
Is it possible to disable the Ctrl key functions? :think:
I have disabled the toolbars but using the Ctrl and "others" keys still allows the user to make amendments and saves etc
eg Ctrl + S Ctrl + B

Bob Phillips
08-24-2007, 12:42 AM
Yes, you can create do-nothing macros and point the keys at your macros



Sub doNothing()
End Sub

'set it somewhere
Application.OnKey "^{c}", "doNothing"

lifeson
09-10-2007, 06:49 AM
Yes, you can create do-nothing macros and point the keys at your macros



Sub doNothing()
End Sub

'set it somewhere
Application.OnKey "^{c}", "doNothing"


Got around to looking at this but am still having issues :think:
I put the code;
Application.OnKey "^{c}", "doNothing"
in the "workbook_open()" code

if the sub "donothing" does not exist then pressing ctrl & S brings up the message:
macro "doNothing" does not exist which shows using the ctrl key is looking for the sub
and nothing happens, which is what I want but without the message

When the "doNothing" macro exists using ctrl & S the workbook saves which is what I was trying to prevent.

Should the code in the workbook open be something like: :dunno

Application.OnKey "^{c}", & 'any other key' "doNothing"

rory
09-10-2007, 07:01 AM
You need to use OnKey for each combination you want to block - so:
application.OnKey "^c", ""
application.OnKey "^S", ""
application.OnKey "^U", ""
...etc.

unmarkedhelicopter
09-10-2007, 07:40 AM
Sometimes when you drag a horse to water it says "I only drink Evian" !

lifeson
09-10-2007, 07:41 AM
Only asking and trying to learn

unmarkedhelicopter
09-10-2007, 07:53 AM
Go on I'll bite, but I'll probably regret it ...

Why did you think putting code in to intercept "Ctrl-c" would do ANYTHING when the user used "Ctrl-s" ???

lifeson
09-10-2007, 10:10 AM
In XLDs first response
Application.OnKey "^{c}", "doNothing"
I assumed ^{c} was the code for the ctrl key and not Ctrl + C and just disabling the Ctrl key would also disable ctrl and any other key aswell

I know have learned that just the ^ indicates the ctrl key

unmarkedhelicopter
09-10-2007, 02:33 PM
Okay, ... I accept that, ... you have my humble appology ... :)

Darren
09-12-2007, 05:12 AM
Hi captains

Just a quick question on the above post about disabling Ctrl keys

Application.OnKey "^{c}", "doNothing"

How would i apply this to the Tab Key on the keyboard ?

Thanks for you help\
Darren
South Africa

rory
09-12-2007, 05:15 AM
You would use:
application.OnKey "{tab}", ""
application.OnKey "+{tab}", ""

If you don't add the second one, they can Shift+tab backwards but not tab forwards.

Darren
09-12-2007, 05:17 AM
Hi Rory

That was quick Thanks Champion

Darren

Darren
09-12-2007, 05:22 AM
Hi Rory

i entered the code as follows but its still active
Option Explicit
Private Sub UserForm_Activate()
TextBox1 = 1#
TextBox2 = 0#
txtTurnoverIncl.SetFocus
Application.OnKey "+{tab}", ""
End Sub
Private Sub UserForm_Initialize()
Dim i As Long
For i = 0 To 35
cmbRoyalty.AddItem Format(i / 100, "0%")
Next i
Application.OnKey "+{tab}", ""
TextBox1.Value = 1#
txtTurnoverIncl = TextBox1
TextBox2.Value = 0
cmbRoyalty.Text = TextBox2
txtTurnoverIncl.SetFocus

End Sub

Your thoughts
Darren

Bob Phillips
09-12-2007, 05:43 AM
I think OnKey is inactive whilst a form is active. But why would you want to disable tab on a form?

rory
09-12-2007, 05:50 AM
My thoughts are many and varied :)
1. You didn't mention a userform before. OnKey does not affect userforms.
2. Why would you want to disable the tab key?
3. Set the TabStop to false for all controls on the form or use the KeyUp event for every control.

Darren
09-12-2007, 11:30 AM
Hi Rory

Sorry i did not mention Userform.

I had chose enter as a navigation key in the useform, Its seems to be a bad choice. looking at tab it seems more user friendly with properties down the left and tabindex set properly works fine.

I have small problem that causes Type Mismatch 13 errors, so i chose enter and backspace as the drivers in the user form. if i enter a number value in userform A say of 2000 in TextBox1 i then use enter and got to Userform B enter a value in TextBox1 on that Userform all is perfect, This is the crunch when i go back to userformA and change the value using delete after 3rd press of delete i get Type Mismatch 13 error. However if i use backspace all is well and no error ?

To summarize i wanted to only use ENTER and BACKSPACE as navigation tools.... so i tried to make TAB and DELETE keys inactive on the userform.

I will use TAB to navigate from now on but if i stop the delete causing error would solve the problem.

I trust my intention is better understood.

Darren
South Africa:beerchug: