OnKeyDown Event

M

mackiaau

When a user keys down on a form - SampleForm, I want to copy the contents of
the form's active control to clipboard. My attempted code is listed below;

Sub CopytoClipboard()

Form("SampleForm").ActiveControl.OnKeyDown.Copy

End Sub

Any help appreciated.
 
D

Dirk Goldgar

mackiaau said:
When a user keys down on a form - SampleForm, I want to copy the contents
of
the form's active control to clipboard. My attempted code is listed below;

Sub CopytoClipboard()

Form("SampleForm").ActiveControl.OnKeyDown.Copy

End Sub

Any help appreciated.


That's not going to work. Something like this might, though the air code
below will work only for controls that have the Text, SelStart, and
SelLength property. Other types of controls will be ignored:

'----- start of air code -----
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

On Error GoTo Err_Handler

Dim lngSelStart As Long
Dim lngSelLength As Long


' NOTE: THIS IS CURRENTLY SET TO OPERATE ONLY IF
' THE ALT+C KEY COMBINATION IS PRESSED.

If KeyCode = vbKeyC And Shift = acAltMask Then

With Me.ActiveControl
lngSelStart = .SelStart
lngSelLength = .SelLength
' If nothing is selected, select the entire text.
If .SelLength = 0 Then
.SelStart = 0
.SelLength = Len(.Text)
End If
RunCommand acCmdCopy
.SelStart = lngSelStart
.SelLength = lngSelLength
End With

End If

Exit_Point:
Exit Sub

Err_Handler:
Resume Exit_Point

End Sub

'----- end of air code -----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top