Results 1 to 5 of 5
  1. #1
    ChuckColeman1812 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jul 2010
    Location
    Springfield, IL
    Posts
    25

    Need to detect right arrow key

    I have a text box on a form that has an input mask. The input mask is:
    09\-09" X "0\-09" X "0\-09;0;_ I have some vba code using the On Exit event
    from the text box where I need to detect if the user used the right arrow key
    AFTER entering the first digit, (in the second position where the 9 allows
    it), to move them to next digit input position. I can't figure out how to


    detect that the right arrow key was used. If the user uses the space bar AFTER
    entering the first digit, no problem; I just look for " ". I've tried
    Mid(TextBoxName, 2, 1) = vbKeyRight but it doesn't work.



    Any ideas?



    Chuck

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    The only events I can think of to use would be KeyDown, KeyUp, KeyPress. The event will trigger for each key stroke in that control.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    ChuckColeman1812 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jul 2010
    Location
    Springfield, IL
    Posts
    25
    Quote Originally Posted by June7 View Post
    The only events I can think of to use would be KeyDown, KeyUp, KeyPress. The event will trigger for each key stroke in that control.
    Thanks, that's helpful. But, I still can't get the system to recognize a right-arrow. Here's what I'm using:

    Private Sub Table_Length_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyAscii = 39 Then
    MsgBox ("Hey, I found a right arrow.")
    KeyAscii = 57
    End If
    End Sub

    If I substitute a 32, (space) for the 39, and I use the space bar instead of the right-arrow key, it works.

    Scratching my head!!!!

    Chuck

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I use KeyPress event to detect CR:
    Private Sub tbxDate_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then

    Chr(39) returns apostrophe character. Not sure what codes for cursor keys are. This seems to indicate 28 is cursor right: http://www.williamrobertson.net/documents/ascii.html

    Also review:
    http://msdn.microsoft.com/en-us/libr...ffice.11).aspx
    http://www.alanwood.net/demos/ansi.html
    http://text-symbols.com/ascii/
    Last edited by June7; 09-12-2012 at 11:24 AM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    ChuckColeman1812 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jul 2010
    Location
    Springfield, IL
    Posts
    25
    I got it to work. Here's what I used:

    Dim KeyCode As Integer
    If KeyCode = 39 Then
    KeyCode = 32
    End If

    In my previous post, I declared KeyCode but didn't use it in the If/Then statement. It must have been late in the day.
    This is triggered on the Key Down event for the text box so it works for every character/right-arrow.

    Thanks for your feedback.

    Chuck

Please reply to this thread with any new information or opinions.

Similar Threads

  1. issues with Enter/Tab/arrow keys clearing fields
    By Kimberly42506 in forum Access
    Replies: 10
    Last Post: 12-16-2011, 03:32 PM
  2. Replies: 0
    Last Post: 11-21-2011, 01:33 PM
  3. Detect When Two Related Fields are Dirty
    By caddcop in forum Forms
    Replies: 2
    Last Post: 06-09-2011, 05:44 AM
  4. How do I detect new records.
    By jcollins in forum Programming
    Replies: 3
    Last Post: 03-17-2011, 03:48 PM
  5. Detect if a row is deleted from a table in the database
    By Hameed Madwar in forum Programming
    Replies: 0
    Last Post: 01-08-2009, 07:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums