Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / February 2006

Tip: Looking for answers? Try searching our database.

Capture CTRL+C event in VBA

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andibevan - 27 Feb 2006 11:53 GMT
I am having problems being able to track when CTRL and C are pressed at the
same time.  I have added the following to the keydown event of my Flexgrid
control:-

If KeyCode = vbKeyD And ((acCtrlMask) <> 0) Then
MsgBox "Ctrl + D Pressed"
End If
'
If KeyCode = vbKeyC And ((acCtrlMask) <> 0) Then
MsgBox "Ctrl + C Pressed"
End If

If I press CTRL+D I get the intended message but nothing if I press ctrl+c -
Any ideas how I can capture CTRL+c.

TIA

Andi
John Nurick - 27 Feb 2006 22:56 GMT
Hi Andi,

I just use the Keypress event and check for the ASCII values of the
control characters, e.g.

Private Sub Form_KeyPress(KeyAscii As Integer)
 Select Case KeyAscii
   Case 3
     MsgBox "Ctrl-C"
   Case 4
     MsgBox "Ctrl-D"
   Case Asc("C")
     MsgBox "C"
 End Select

As for the problem with your code, I haven't tried to think it through
completely, but the value of acCtrlMask is 2, so this
    acCtrlMask <> 0
always evaluates to True.

If you want a condition that is true only when the Control key is
pressed, you need
    (Shift And acCtrlMask) > 0

For more, see Help, or
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaac11/html/ac
evtKeyDown_HV03079790.asp


>I am having problems being able to track when CTRL and C are pressed at the
>same time.  I have added the following to the keydown event of my Flexgrid
[quoted text clipped - 14 lines]
>
>Andi

--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
Andibevan - 28 Feb 2006 12:42 GMT
Hi John - Thanks for your suggestion but unfortunately it didn't work form
me.

This may because the flexgrid has the focus rather than the form.  As a
result I moved your code to the Flexgrid keypress event and it still doesn't
work.

If I add the line debug.print keyascii - most combinations of keypresses
(i.e. ctrl+d, ctrl+r) work and generate an ascii value in the immediate
window.  When I do ctrl+c, ctrl+v or ctrl+x - no ascii values are
generated - it seems as though the combination of ctrl+c triggers some event
elsewhere.

Still Stumped

Andi

> Hi Andi,
>
[quoted text clipped - 21 lines]
>
> For more, see Help, or

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaac11/html/ac
evtKeyDown_HV03079790.asp


> >I am having problems being able to track when CTRL and C are pressed at the
> >same time.  I have added the following to the keydown event of my Flexgrid
[quoted text clipped - 19 lines]
>
> Please respond in the newgroup and not by email.
John Nurick - 28 Feb 2006 21:26 GMT
I dunno. I've never used a Flexgrid, but Ctrl-C, Ctrl+X and Ctrl-V are
pretty suggestive: sounds like something is intercepting the clipboard
shortcuts before the keystroke is passed to the Flexgrid. Does the
active cell (or whatever it's called) of the Flexgrid have its own
keystroke events?

One thing that's worth trying is to set the Form's KeyPreview property
to True, and see if you can pick up these keystrokes in the Form's
keypress event. That should short-circuit any funny business with the
Flexgrid.

>Hi John - Thanks for your suggestion but unfortunately it didn't work form
>me.
[quoted text clipped - 67 lines]
>>
>> Please respond in the newgroup and not by email.

--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.