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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable Keys in MSAccess? 2

Status
Not open for further replies.

paulbradley

Programmer
Oct 9, 2002
158
GB
Is there a way of being able to disable alt-tab, ctrl-escape and other windows things like that so that my users cannot get out of the access program unless the press and exit button i design in my forms.

Thanks.
 
Paul,
You can set the KeyPreview property on your form, then in the KeyPress (or maybe it's the KeyDown) event, check if the ctl/alt etc. keys are pressed (look for the key combinations you want to disallow), and cancel the event if they are.

Hope that helps.

Tranman (also a Paul)
 
I don't really know what the KeyPreview button does and how to chekc if keys are pressed. I don't think this solution would work as the key detect things are in windows and you would have to overwrite that.
 
I'm not sure I understand your question.

Do you want the users not to be able to use other programs while this access db is running (no e-mail, no Word...)? I don't know if that's possible.

If it's more the question of disabling the possibilities of exiting forms/database thru CTRL+W, CTRL+F4, the x button, ALT+F4... then my favourite approach is described in mstrmage1768's faq faq702-1870. In my experience, the only way to quit without the "appropriate" button, is cutting the power or using the task manager.

Roy-Vidar
 
Paul
Without going into what you're trying to achieve this will disable just about everything in win95 (yes, that's what I still use!)

Code:
Private Const SPI_SCREENSAVERRUNNING = 97&
Private Declare Function SystemParametersInfo Lib "User32" _
Alias "SystemParametersInfoA" _
(ByVal uAction As Long, _
ByVal uParam As Long, _
lpvParam As Any, _
ByVal fuWinIni As Long) As Long


Private Sub Disable()
Dim lngRet As Long
Dim blnOld As Boolean
lngRet = SystemParametersInfo(SPI_SCREENSAVERRUNNING, True, _
blnOld, 0&)
End Sub

Private Sub Enable()
Dim lngRet As Long
Dim blnOld As Boolean
lngRet = SystemParametersInfo(SPI_SCREENSAVERRUNNING, False, _
blnOld, 0&)
End Sub

From a practical point of view, I was using stuff like this (or planning to) a while ago to lock down student access. While researching it I have a feeling that this isn't recommended in NT, and so I suppose XP either.

Or that might have been while I was trying to disable the taskbar!

;-)


If a man says something and there are no women there to hear him, is he still wrong? [ponder]
The faqs ma'am, just the faqs. Get the best from these forums : faq222-2244
 
Loomah - how would I use your code? Where would I place and run it?

RoyVidar - thanks but the FAQ will still allow the user to minimise the program (which I have running full screen, no task bar or anything) of change to another program using alt-tab, ctrl-esc etc.

Any other options?
Thanks.
 
Paul
I'm no Access programmer (mainly Excel) so I'd only be guessing.

I'd suggest something like running Disable() from the Form Load routine and Enable() from your Exit button and at the end of your routine, once it's run it's natural course.

I think the code will have to be held in it's own module and scoped appropriately (Public/Friend as opposed to Private). I only used it in a pure VB context.

Before you use it, run it in isolation to see what it does, with nothing else (crucial) open on your PC, from any module.

At this point I'd re-iterate the warning that comes with this code and add the fact that CTRL+ALT+DEL will also be disabled. Consider the consequences of this should your app fall over.

Good Luck & enjoy!
Happy Friday
;-)

If a man says something and there are no women there to hear him, is he still wrong? [ponder]
The faqs ma'am, just the faqs. Get the best from these forums : faq222-2244
 
Still niot sure, and can't get it working - any VB programmers able to give me more specific details?

Thanks again.
 
Paul
I don't know what else to say. I've just had a quick look on the internet to see if there is anything to suggest this won't work with a NT based OS (I'm assuming thats's what you have.) Can't find anything!

I don't know why it doesn't work. If you haven't got VB (and I'm not using VB here) copy the code into any module of any office app. As this is working on Windows, the application is irrelevant, as long as it understands VB.

Run the Disable sub. Can you still use the key combos you want to disable?

Then run the Enable sub. Can you now use the key combos again?

The next step is to look at which events in Access you will need to use to trigger the code. Things like UserForm_Initialize or its Access equivalent to disable and something like UserForm_Terminate to re-enable but also to add the Enable code to your Exit button.

;-)

If a man says something and there are no women there to hear him, is he still wrong? [ponder]
The faqs ma'am, just the faqs. Get the best from these forums : faq222-2244
 
As I stated in previously reply, I don't know if this is possible. Myself I'm happy enough with a controlled exit of the application. Here are some thoughts though:

There are several challenges here, one of them is using a maximised form, see for instance this Microsoft KB article.

Anyway, I've found trapping keystrokes a bit hard, but it might be that I've got extra pesky users?

The Access AutoKeys macro does come to mind, it should trap for CTRL and SHIFT combinations while the app is open (i e for usage as custom shortcut keys). Haven't tried it much, but I don't seem to get it to work the way I like (having problems with SHIFT and ALT).

Then as Loomah elaborates a bit on, using form events. For instance the forms KeyDown event might be used on each form (with form KeyPreview = True). No need to disable them in access, though, they "die" when the form closes. But what happens when you open a report, these events work only on forms, so no keytrapping there...

Finding a way to make the access db/application modal, would probably be the best. Just entered a simple search on microsoft, and found this Microsoft KB article, on making Access modal, but sadly enough, the lates version that applies for, is Access 2.0. But do give search a try, either on Google, other search engines, here on TT...

BTW - there are also Access specific fora here, take a look at the "Related forums" box, just below the forum mvp list. Perhaps some of the members in Access VBA forum, or VB might have more specific knowledge...

Roy-Vidar
 
Many thanks for all that help, it's much appreciated. I'll do some more looking on the net and other forums perhaps. Fortuantly it's not essensial I get this working but again, thanks for all your help.

Regards,
Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top