Solved

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

Posted on 2014-01-06
7
74 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

896 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

12 Experts available now in Live!

Get 1:1 Help Now