Solved

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

Posted on 2014-01-06
7
83 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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
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 …

821 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