Link to home
Start Free TrialLog in
Avatar of cfg1980
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.

Avatar of jefftwilley
jefftwilley
Flag of United States of America image

Here's something close

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
ASKER CERTIFIED SOLUTION
Avatar of jefftwilley
jefftwilley
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cfg1980
cfg1980

ASKER

That was exactly what I was looking for....thank you!