Solved

Capture Key Codes within a Text Box

Posted on 2006-12-01
3
683 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

744 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now