Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Capture Key Codes within a Text Box

Posted on 2006-12-01
3
Medium Priority
?
742 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 500 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

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

972 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