cfg1980
asked on
Capture Key Codes within a Text Box
I'm trying to capture certain key strokes within an Access application. I've been using this function:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyDelete
'User pressed the Delete key
End Select
End Sub
However, this only seems to work when they are not inside of a text box. I'm looking to capture these key strokes when they are entering data into a text box. Is this possible? Thanks in advance for your help.
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyDelete
'User pressed the Delete key
End Select
End Sub
However, this only seems to work when they are not inside of a text box. I'm looking to capture these key strokes when they are entering data into a text box. Is this possible? Thanks in advance for your help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That was exactly what I was looking for....thank you!
Dim WholeString As String
Dim LengthString As Long
--------------------------
Private Sub data1_Change()
Dim myStr As String
Dim strPos As Long
strPos = Len(Me.data1.Value)
myStr = Right(Me.data1.Value, strPos - LengthString)
WholeString = WholeString & myStr
LengthString = strPos
End Sub
--------------------------
Private Sub data1_GotFocus()
WholeString = ""
LengthString = 0
End Sub
--------------------------
Private Sub data1_LostFocus()
MsgBox WholeString
End Sub