Solved

Disable Ctrl+Apostrophe (Ctrl+') in access 2010

Posted on 2014-01-06
7
68 Views
Last Modified: 2016-05-14
I would like to prevent users from using Ctrl+' in forms and tables in Access 2010.

I was able to get a form to stop the Ctrl+' by setting KeyPreview for the form to Yes and placing a msgbox statemetn in the KeyDown event when keycode equaled 17 (Ctrl mask).  Is there a way to detect the Ctrl key as well as the apostrophe key so I won't have to use a msgbox statement?  

Searching of the internet suggests setting keycode = 0 but that doesn't work without the msgbox statement.
0
Comment
Question by:lunanat
7 Comments
 
LVL 10

Expert Comment

by:Anthony Berenguel
ID: 39759571
If I understand you correctly, try using DoCmd.CancelEvent instead of the message box whenever the apostrophe key is pressed.
0
 
LVL 10

Expert Comment

by:Anthony Berenguel
ID: 39759580
if KeyCode = 39 then 
   'the apostrophe key was pressed
   DoCmd.CancelEvent
end if

Open in new window

0
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 39759670
This is how to do it:

Private Sub txtTextBox_KeyDown(KeyCode As Integer, Shift As Integer)
   
    If KeyCode = 191 Then
        If (Shift And acCtrlMask) > 0 Then
            KeyCode = 0
        End If
    End If

End Sub

/gustav
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Author Comment

by:lunanat
ID: 39760121
Thank you for your reply.

Docmd.CancelEvent  did not work

I was able to get following code to work for a control on an Access 2010 form. Note that KeyPreview was set = YES for the form.

Private Sub txtTextBox_KeyDown(KeyCode As Integer, Shift As Integer)
    If (Shift And acCtrlMask) > 0 Then
        KeyCode = 0
    End If
end Sub

This code also works for the KeyDown event procedure on the form property.  KeyPreview was set = YES for the form.
0
 
LVL 1

Author Comment

by:lunanat
ID: 39766589
The following code prevents the copying of field contents from the previous record when applied to the Form_keyDown event.  The KeyPreview property must = yes (ie be true).

The code can also be inserted into the keydown event of an individual control

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

    ' Trap the Ctrl+H key combination to disable Replace
    ' The form's KeyPreview property must be True
Dim intCtrl As Integer
intCtrl = (Shift And acCtrlMask) > 0 ' Test for Ctrl key
If intCtrl And KeyCode = 222 Then ' Ctrl+' pressed
    KeyCode = 0 ' Throw out the keystrokes
End If
End Sub
0
 
LVL 26

Expert Comment

by:MacroShadow
ID: 41594505
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now