Results 1 to 7 of 7
  1. #1
    RichardAnderson is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2013
    Posts
    74

    Possible?? Arrow Up/Down to increase/decrease value in number field


    Hello folks,

    Is this possible? I have a form with a number field that has a default value from a related table. When the use is entering a new job, and they want to increase the number, it would be nice to be able to use the up/down arrows to just increase the number by 1 or 2.

  2. #2
    NTC is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Posts
    2,392
    generically speaking; yes one can certainly increment numbers by the OnClick event of a button.

    the specifics of how to do so in your case would depend on how your data is set up. Also I'm not sure what you mean by "the up/down arrows" as if there are some particular arrows you are refering to rather generically to a button added in design view.

    one method is vba code: me.FieldName = me.FieldName +1
    another method is to trigger an UpdateQuery and then requery the form to display the new info

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    Just replace TargetControl with the actual name of your Textbox:
    Code:
    Private Sub TargetControl_KeyDown(KeyCode As Integer, Shift As Integer)
      
      Select Case KeyCode
        
       Case vbKeyDown
       
          Me.TargetControl = Nz(Me.TargetControl, 0) - 1
    
       Case vbKeyUp
       
          Me.TargetControl = Nz(Me.TargetControl, 0) + 1
    
      End Select
    
    End Sub

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    RichardAnderson is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2013
    Posts
    74
    I am so sorry for the confusion as to what I mean by up/down arrows. I am refering to the arrow keys on the keyboard.

  5. #5
    RichardAnderson is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2013
    Posts
    74
    Linq,

    Your code works but the arrow keys still move focus either back 1 or forward 1 in the tab order. I tried to put your code in the onkey down and a focus command in onkey up, but that doesnt work. I am thinking I may need to disable the default function of the arrow keys somehow.

    Thank you for your effort

  6. #6
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    It may have to do with how your options are set, but the arrows work as normal, for me, except when the target control has the focus. At any rate, try this:
    Code:
    Private Sub TargetControl_KeyDown(KeyCode As Integer, Shift As Integer)
      
      Select Case KeyCode
        
       Case vbKeyDown
       
          Me.TargetControl = Nz(Me.TargetControl, 0) - 1
          KeyCode = 0
          
       Case vbKeyUp
       
          Me.TargetControl = Nz(Me.TargetControl, 0) + 1
          KeyCode = 0
    
      End Select
    
    End Sub
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Linq,

    Do you need to have the form "Key Preview" event set to Yes/True??? (properties/Event tab)

    I recall reading something about this.... "Key Preview" affects who gets the event first: the form or the control.

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

Similar Threads

  1. Need to detect right arrow key
    By ChuckColeman1812 in forum Programming
    Replies: 4
    Last Post: 09-12-2012, 08:08 AM
  2. issues with Enter/Tab/arrow keys clearing fields
    By Kimberly42506 in forum Access
    Replies: 10
    Last Post: 12-16-2011, 03:32 PM
  3. Replies: 0
    Last Post: 11-21-2011, 01:33 PM
  4. Increase Size of Field Name
    By tonere in forum Database Design
    Replies: 5
    Last Post: 06-27-2011, 02:30 PM
  5. Increase number by 1
    By elstiv in forum Queries
    Replies: 2
    Last Post: 05-14-2011, 12:25 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