Solved

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

Posted on 2014-01-06
7
96 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 50

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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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 27

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

696 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