Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable Control Button on Keyboard 2

Status
Not open for further replies.
Jun 2, 2004
66
US
I am trying to disable the Ctrl button while users are in a form. I do not want them to be able to use any of the ctrl + shortcuts for printing...find/replace etc....


I have used a similar code for disabling the F keys, but for some reason it is not working for the ctrl button. Here is what I tried.

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyControl Then KeyCode = False
End Sub

Any ideas?

Thanks
 
Try investigating the Shift parameter/arguement:
[tt]if (shift and acCtrlMask)>0 then
' Control is pressed
end if[/tt]

Roy-Vidar
 
Wanna know how?

I gave you how to determine when the CTRL button is pressed, but left out how to disable/cancel it - in relation to RickSpr's faq faq181-2886, I was perhaps a bit #2, but I felt a little #8 wouldn't hurt, and also we wouldn't like to become #10 would we?

Here's one method, disabling both the "shift" and keycode (though it should be enough to disable the keycode, I think)

[tt]if (shift and acCtrlMask)>0 then
keycode=0
shift=0
end if[/tt]

Grumpy, old Roy-Vidar;-)
 
Roy,
Thanks very much for your assistance. I'm certainly not looking to become someone who belongs in #10. Have a good one.

INYH
 
Sorry for having to reintroduce this issue, but the code that I used above works, but for some reason it does not allow my users to enter data into the text boxes of my Access form.

As stated above, my objective is to freeze the "F" keys and any "ctrl" functions while users are in the form. I used the below code to freeze the "F" keys and it works like a charm. When I add Case 17 (to freeze the ctrl button)it does not work. Any ideas?

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 17, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123
KeyCode = 0
End Select
End Sub
 
Here you're probably testing for the control key, but using the Shift arguement, you can trap for any combination. For instance:

[tt]if (shift and acCtrlMask)>0 then
keycode=0
shift=0
else
select case vbkeycode
case vbkeydivide, vbkeyf1, vbkeyf2, vbkeyf3, vbkeyf4, vbkeyf5, vbkeyf6, _
vbkeyf7, vbkeyf8, vbkeyf9, vbkeyf10, vbkeyf11, vbkeyf12
keycode=0
end select
end if[/tt]

I like using the constants, makes the code a bit more readable - been off for the weekend, sorry for the delay...

Roy-Vidar
 
sorry for hitchhiking this one ...

has anyone seen a solution to disallow certain keycombinations? (e.g. disallow the ctl+f but allow ctl+c and ctl+v)??

Many thanks in advance,
Bye,
fly

[blue]Typos, that don't affect the functionality of code, will not be corrected.[/blue]

Martin Serra Jr.
[blue]Shared Database_Systems and _Applications across all Business_Areas[/blue]
 
Just play with the constants, sonmething like this would disallow ctrl+f, I think, and allow any other combinations. As stated previously in this thread, F1 is a great help - there's a sample in the help topic on the keydown event.

[tt]if ((shift and acCtrlMask)>0 and (keycode = vbkeyf)) then
keycode=0
shift=0
end if[/tt]

Roy-Vidar
 
Thank you, enjoy a star.
Martin

[blue]Typos, that don't affect the functionality of code, will not be corrected.[/blue]

Martin Serra Jr.
[blue]Shared Database_Systems and _Applications across all Business_Areas[/blue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top