Create custom shortcut key

G

Guest

I have a user that wants to use Alt+s as a keyboard shortcut to enter§ into
text fields. How can this be done.§ is the legal section symbol and can be
entered by using Alt+0167 but she wants to use Alt+s. Thanks
 
G

Guest

Try putting the following in the control's KeyDown event procedure:

' inserts symbol § at insertion point
' if Alt+s pressed
Const conS = 83
Dim ctrl As Control
Dim intPos As Integer, intLength As Integer

Set ctrl = Me.ActiveControl
intPos = ctrl.SelStart
intLength = ctrl.SelLength

If (Shift And acAltMask) = acAltMask Then
If KeyCode = conS Then
ctrl = Left(ctrl.Text, intPos) & Chr(167) & _
Mid(ctrl.Text, intPos + 1 + intLength)
ctrl.SelStart = intPos + 1
ctrl.SelLength = 0
End If
End If

Ken Sheridan
Stafford, England
 
G

Guest

Your solution worked. Thanks

Ken Sheridan said:
Try putting the following in the control's KeyDown event procedure:

' inserts symbol § at insertion point
' if Alt+s pressed
Const conS = 83
Dim ctrl As Control
Dim intPos As Integer, intLength As Integer

Set ctrl = Me.ActiveControl
intPos = ctrl.SelStart
intLength = ctrl.SelLength

If (Shift And acAltMask) = acAltMask Then
If KeyCode = conS Then
ctrl = Left(ctrl.Text, intPos) & Chr(167) & _
Mid(ctrl.Text, intPos + 1 + intLength)
ctrl.SelStart = intPos + 1
ctrl.SelLength = 0
End If
End If

Ken Sheridan
Stafford, England
 

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