Key Press Question (1 Viewer)

gregorg

Registered User.
Local time
Today, 01:57
Joined
Jul 26, 2006
Messages
56
Hi I want to set the focus to a text box when i press "Ctrl X" on the form.

What event should I use ?

What is the code to let me do this ?

Can you help ? Gregor.
 

LPurvis

AWF VIP
Local time
Today, 01:57
Joined
Jun 16, 2008
Messages
1,269
Hi

You'll want to set the Form property "Key Preview" to true (Yes) and then something like...

Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    
    If KeyCode = 88 And Shift = 2 Then
        'Ctrl x pressed
        DoCmd.CancelEvent
        Me.txtBoxName.SetFocus
    End If
    
End Sub

Cheers.
 

gregorg

Registered User.
Local time
Today, 01:57
Joined
Jul 26, 2006
Messages
56
---THANKS---

Gregor.
 

gregorg

Registered User.
Local time
Today, 01:57
Joined
Jul 26, 2006
Messages
56
Can i ask, why you have the cancelEvent in there ?
 

LPurvis

AWF VIP
Local time
Today, 01:57
Joined
Jun 16, 2008
Messages
1,269
Well it was a slight assumption - but a common one when redirecting key combinations to another action.
It basically cancels the UI action that raised the event. So in this case, since Ctrl X would normally cause a Cut, it cancels that action and performes the code based alternative only.
It occurs to me that you might have wanted this functionality to both cut and automatically set focus to one given control into which you would be pasting the cut text. That's fair enough - but there are alternatives to "moving" text between controls if you so chose.
Just remove that line if you still want the standard Windows Cut operation to occur.

Cheers.
 

Users who are viewing this thread

Top Bottom