Executing repetitive code with arrow keys (1 Viewer)

pitoten

New member
Local time
Yesterday, 22:46
Joined
Apr 23, 2018
Messages
7
Hello, I am new to the forum. Please let me know if I am not following any best practice rules for posting.

I am using a boolean object variable to execute some repetitive code if the user holds down either the keyboard arrow keys, or some command buttons on a form (user's choice). The user enters a number in a textbox and can use the keyboard arrows or the command buttons to move a few controls around. The repetitive code seems to work well. However, I would like the number in the input textbox to be highlighted after the user stops pressing the arrow or command button, and this does happen after the user lets go of any of the command buttons, as well as the up arrow on the keyboard, but not the right, left, or down arrows :confused:. Any ideas?

I want the number to be highlighted so the old number is erased as the new number is entered.

Any help would be much appreciated. Thanks!
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 11:46
Joined
May 7, 2009
Messages
19,243
In cimmand button click event add code:

On error resume next
Dim ctl as control
Set ctl=screen.activecontrol
If typeof ctl is textbox or typeof ctl is combobox then
Ctl.selstart=0
Ctl.sellength=len(ctl.text)
End if
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 22:46
Joined
Feb 28, 2001
Messages
27,185
Please note that holding down a physical key engages a hardware-based repetition. Holding down a cursor on a command button on a form does not. I believe the Mouse-based Click event occurs AFTER the Mouse Up event, so technically a mouse click doesn't occur until you release the mouse button #1. A key-press (particularly such as the space bar or enter key) could have the same effect as a control's Click event in some cases, but it IS based on a separate event - the KeyPress event.
 

pitoten

New member
Local time
Yesterday, 22:46
Joined
Apr 23, 2018
Messages
7
Please note that holding down a physical key engages a hardware-based repetition. Holding down a cursor on a command button on a form does not...


Is it possible that arrow key presses are getting stuck in the keyboard cache and then acting the same way as TAB does, tabbing over to another control on the form after the keydown/keyup events end? And if so, how could I stop that from happening? Any other advice would be appreciated. I've been messing around with it for awhile, but to no avail...

Also, if the focus is initially on some other control other than the input box before the keydown event, the desired text in the input box is highlighted after keydown/keyup, but if the focus is on the input box and text highlighted before keydown, then the focus moves to another control after keydown, which is unwanted. :confused:

Let me know what you think, and thanks for your time.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 22:46
Joined
Feb 28, 2001
Messages
27,185
The behavior of arrow keys (and some other keys) is, I believe, programmable in the File >> Options >> Current Database path to get to a whompin'-complex tabbed dialog box. Check the settings in that dialog box to see what your keys are being asked to do. Among other things, you can define how the return key works, what a space-bar does for (some) controls, and I think there are some "edit" options involving the arrow keys that you can get to.

It has been a while since I played with this and I'm not sure which version of Access you are using, so before I go overboard, just see if that path leads you to something useful. If it doesn't, then I need to know which version of Access you are using before I could hope to answer. But if it is as recent as Ac2007, that path should be valid and lead you to the options page.
 

pitoten

New member
Local time
Yesterday, 22:46
Joined
Apr 23, 2018
Messages
7
Thanks Doc, I am using Access 2016. I will monkey around with the options you talked about and get back to you soon. Thanks for trying to help me out :eek:.

P.
 

pitoten

New member
Local time
Yesterday, 22:46
Joined
Apr 23, 2018
Messages
7
Hi Doc,

I've been doing a little experimenting and hunting around, and I found arrow key behavior under File>Options>Client Settings, I couldn't find the tabbed dialogue box you were referring to in Current Database. I switched arrow key behavior to the selection that makes the focus stay with the input text box, so that is at least a start. The text inside the box however gets unhighlighted. I decided to see what would happen if I changed the keys that fire the code to other keys on the keyboard, and wouldn't you know it, it works just as I want it to, other than the fact that I have to use obscure keys to get the job done when the arrow keys are right there, which is undesirable. When I use the left key, the cursor goes to the left of the text, and the right key moves it to the right of the text, which leads me to believe that the arrow keys are both working to fire the event as well as move the cursor around in the input box. I looked all over for a way to disable the cursor movement, but to no avail, not sure if it's possible.

While I was testing things, I also ran into another unexpected problem with using the arrow keys...an out of stack space error. I have a doevents in the sub that I call (the same one that the cmd buttons calls), and the stack gets blown when using the arrow keys but it does not happen when using the command buttons. Is it the case that using the command buttons clears the stack space as it goes while the arrow keys do not? And if so, how can I get the arrow keys to behave like the command buttons? Any advice would be appreciated, I know it sounds like a mess, I'm just hoping I'm missing something obvious in the code or there is some way to clear the stack space as i go when using the arrow keys, or there is some other strategy that I'm not aware of.

Let me know what you think,

P. :(
 

Users who are viewing this thread

Top Bottom