Solved

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

Posted on 2014-01-06
7
114 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 
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

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…

688 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