Enter a key that simulates a click that does not work for checkboxes

I copied and slightly modified the code found at the bottom of this post to allow tabs between the controls in the sheet form I created. Here is the segment related to KeyCode = vbKeyEnter:

Select Case KeyCode Case vbKeyTab Dim Backward As Boolean Backward = (Shift And fmShiftMask) Call MoveFocus(Cntrl:=Cntrl, TabIndex:=TabIndex, Backward:=Backward) Case vbKeyEnter Select Case TypeName(Cntrl) Case TxtBoxType If Not (Cntrl.EnterKeyBehavior And Cntrl.MultiLine) Then Call MoveFocus(Cntrl:=Cntrl, TabIndex:=TabIndex) End If Case Else On Error Resume Next Application.Run Sheet1.CodeName & "." & Cntrl.name & "_Click" On Error GoTo 0 End Select End Select 

The code works great for moving back and forth between controls. However, I am having problems using the enter key to check and uncheck the boxes. It works for the parameter buttons, but does not work. If I add CheckBox1.Value = True to the CheckBox1_Click event, it works to check it is true, but, of course, will not allow it to uncheck it. I tried adding the following IF statement to set it to true or false depending on the current value, but then nothing happens.

 If CheckBox1.Value = True Then CheckBox1.Value = False Else CheckBox1.Value = True End If 

Another note. When I press enter and nothing happens with the form control, it moves the active cell down the active column. Any suggestions?

+3
source share
1 answer

This may or may not be the answer to a programming question; I will let voters decide.
Q. Enter key simulate click does not work for checkboxes

Why are you doing this? You are wasting time and effort deliberately “breaking” the work system. spacebar has long been an accepted keystroke to enable or disable the checkbox, Tab and Shift + Tab are used to navigate between form controls, and Enter↵ is the default value for OK .

By "working system" I mean the entire GUI system for Mac / Windows / Linux and millions of people who are trained to work within the framework of long-defined standard practices. You can distract the mouse from any competent employee and their performance will not be affected. They can navigate through the system and applications to do their job, because everything in the system, from setting the video resolution to entering the working hours of workers in a user form, works the same way .

Take a Windows user and tie it in front of your first Mac. They can use programs and do their job, because the vast majority of operations (and, in particular, for the main work of the application) are the same. Take the Mac user and bind him in front of the Linux machine, and you will get the same results. The basic daily work of the machine and its programs is the same.

What is the point of any potential job seeker to get a CV filled with office experience if you intend to create a proprietary system that takes all their training, practice and experience and puts them out of the window?

Using the spacebar option to enable or disable the check box precedes Windows 3.0. There is a difference between building a better mousetrap and reinventing the wheel.


¹ If you don’t think that maintaining GUI standards is something you should strive for, think about the reaction that Office 2007 Ribbon created. The entire sub-industry was created to create add-ins that led to Office 2003 functionality.

+4
source

Source: https://habr.com/ru/post/925314/


All Articles