Help with Alt+1 shortcuts.

T

ThomasAJ

I have a string that I wish to write to a text field when Alt+1 is pressed.
The following code does not work as the form's KeyDown event is executed when
the Alt key is pressed and at that time it does not know that the '1' key has
been pressed.

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

Dim blnAlt As Boolean

blnAlt = (Shift And acAltMask)

If blnAlt Then
If (KeyCode = vbKey1) Then SendKeys strAlt1, True
End If

End Sub
 
S

Stuart McCall

ThomasAJ said:
I have a string that I wish to write to a text field when Alt+1 is pressed.
The following code does not work as the form's KeyDown event is executed
when
the Alt key is pressed and at that time it does not know that the '1' key
has
been pressed.

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

Dim blnAlt As Boolean

blnAlt = (Shift And acAltMask)

If blnAlt Then
If (KeyCode = vbKey1) Then SendKeys strAlt1, True
End If

End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If (Shift And acAltMask) = acAltMask Then
If KeyCode = vbKey1 Then
MyTextField = MyString
KeyCode = 0 'IMPORTANT - "throw away" the keypress
End If
End If
End Sub

Obviously you need to replace:

MyTextField = MyString

with your names.
 

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