Problem in capturing keystrokes and change the KeyCode to TextBox input (1 Viewer)

Alan Chan

Registered User.
Local time
Tomorrow, 05:02
Joined
Aug 28, 2013
Messages
14
Dear experts,

To facilitate input of special graphic characters such as the degree C and plus-and-minus symbols, I would like to use Alt-1 to Alt-9 key combinations, capture these keys in a KeyDown event procedure and change the keystroke to the desired graphical character code. I am using Access 2010 on Win7.

I first attempted to change the Shift integer to zero to reset the Alt-bit and set KeyCode to the desired character code, but this does not work.

Hence I try to use the second common method of setting KeyCode to zero and use SendKeys to VBA-input the desired graphic character. However, strange things happens.

The test code is as follows:

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

Dim i As Long

If (Shift And acAltMask) <> 0 And KeyCode <> 18 Then

' For i = 1 To 20000000 this For-loop is initially commented out
' Next i

MsgBox "Key changed"
KeyCode = 0
SendKeys ("#")
End If
End Sub

The above code as it is works OK and the '#' is successfully inputted to the TextBox field.

However, if I comment out the MsgBox statement, the program waits for about 0.3 second and then instantly fills up the entire TextBox field by a large number of '#' characters.

If I move the MsgBox statement to after the SendKeys, no '#' character is inputted to the TextBox.

If I comment out the MsgBox statement and activate the For loop at the looping count amount (but not much less), the program works fine.

It appears that there is some sort of internal timing problem inside Access.

Any suggestion for resolution is much appreciated.

Thanks.

Alan Chan
 

Users who are viewing this thread

Top Bottom