Short cut to insert text (1 Viewer)

latex88

Registered User.
Local time
Yesterday, 21:11
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.
 

bat1799

Registered User.
Local time
Today, 03:11
Joined
Nov 18, 2005
Messages
27
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
 

latex88

Registered User.
Local time
Yesterday, 21:11
Joined
Jul 10, 2003
Messages
198
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"?
 

ghudson

Registered User.
Local time
Yesterday, 22:11
Joined
Jun 8, 2002
Messages
6,195
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.
 

bat1799

Registered User.
Local time
Today, 03:11
Joined
Nov 18, 2005
Messages
27
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

Top Bottom