Create custom shortcut key

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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
 
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
 
Back
Top