Short cut to insert text

latex88

Registered User.
Local time
Today, 14:21
Joined
Jul 10, 2003
Messages
198
Is there a way to assign some short cut controls that will insert certain text into the field the cursor is in? For example, is there a way to assign "No mustard" to Alt-M, so when Alt-M is pushed, "No mustard" is inserted to the field.
 
Try
Code:
Private Sub YourControl_KeyDown(KeyCode As Integer, Shift As Integer)
    Dim intShiftDown As Integer, intAltDown As Integer
    Dim intCtrlDown As Integer
    ' Use bit masks to determine which key was pressed.
    intShiftDown = (Shift And acShiftMask) > 0
    intAltDown = (Shift And acAltMask) > 0
    intCtrlDown = (Shift And acCtrlMask) > 0
    If intAltDown And KeyCode = 77 Then
        Me.YourControl = "No mustard"
        KeyCode = 0
    End If
  End Sub

See this link for more details

http://msdn.microsoft.com/library/d...n-us/vbaac11/html/acevtKeyDown_HV03079790.asp

Peter
 
hmmm. The code doesn't seem to work. Do I need to set the property of the form to something first? Also, I'd presume KeyCode, 77, is "M"?
 
latex88 said:
hmmm. The code doesn't seem to work. Do I need to set the property of the form to something first? Also, I'd presume KeyCode, 77, is "M"?
Turn the forms 'event' KeyPreview property to Yes.
 
Lowe case "m" I think.
The code as is will only work in the field its coded to run in. to make it run at anytime you will need to do as ghudson says and run the code from the forms keypress event.

to find kecodes use
debug.print KeyCode
in the event and it will print each press to the debug window (ctr-G)

HTH

Peter
 

Users who are viewing this thread

Back
Top Bottom