Solved

Capture Key Codes within a Text Box

Posted on 2006-12-01
3
722 Views
Last Modified: 2008-03-03
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.

0
Comment
Question by:cfg1980
  • 2
3 Comments
 
LVL 34

Expert Comment

by:jefftwilley
ID: 18056347
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
0
 
LVL 34

Accepted Solution

by:
jefftwilley earned 125 total points
ID: 18056399
This one works too

Private Sub data1_KeyDown(KeyCode As Integer, Shift As Integer) ' Where Data1 is the name of your textbox
 Select Case KeyCode
      Case vbKeyDelete
        MsgBox "User pressed the Delete key"
    End Select

End Sub
0
 

Author Comment

by:cfg1980
ID: 18056485
That was exactly what I was looking for....thank you!
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question