locked
HOW TO CREATE A SPECIFIC KEY PRESS AN INVISIBLE BUTTON IN FORM? RRS feed

  • Question

  • OK, so I have 4 buttons (cmdLeft, cmdRight, cmdUp, and cmdDown) these buttons move subform controls to different parts of the main form. I want to make these buttons invisible and instead make the arrows on the keyboard make the buttons click. How can I do something like this?
    Monday, August 21, 2017 12:30 PM

Answers

  • Well, you never stated anything about a toggle button. The developers here try to advise as best as we can with what information you tell us. Poor design that frustrates users is not going to get you in their good graces. Hence, we try to discourage unusual design.

    Now knowing you have a toggle I'd say using the arrows would be okay. Your main form must have the key preview turned on. Then use the KeyPress or KeyDown events to capture the arrows. There are lots of examples on the internet.


    Bill Mosca
    www.thatlldoit.com
    http://tech.groups.yahoo.com/group/MS_Access_Professionals

    • Marked as answer by InnVis Monday, August 21, 2017 4:56 PM
    Monday, August 21, 2017 2:35 PM
  • Hi,

    There's lots of ways to possibly handle this. Have you tried sending the focus back to the main form when you click on the button? For example:

    Me.Parent.ControlName.SetFocus

    Hope it helps...

    • Marked as answer by InnVis Monday, August 21, 2017 4:55 PM
    Monday, August 21, 2017 4:50 PM

All replies

  • I really don't advise commandeering the arrows on the user's keyboard. It can be done with SendKeys but it would probably annoy the user. Any good Access application should be intuitive.

    Bill Mosca
    www.thatlldoit.com
    http://tech.groups.yahoo.com/group/MS_Access_Professionals

    Monday, August 21, 2017 1:55 PM
  • Why would the user be annoyed? I don't understand. In my subforms I have a button that can toggle on and off. If the button is on, then the subform can be moved, if it's off then the form can't be moved (with the buttons on the form). I just want to replace the buttons with the keyboard arrows instead... which I find much more user friendly then clicking a button a thousand times.
    Monday, August 21, 2017 1:57 PM
  • Well, you never stated anything about a toggle button. The developers here try to advise as best as we can with what information you tell us. Poor design that frustrates users is not going to get you in their good graces. Hence, we try to discourage unusual design.

    Now knowing you have a toggle I'd say using the arrows would be okay. Your main form must have the key preview turned on. Then use the KeyPress or KeyDown events to capture the arrows. There are lots of examples on the internet.


    Bill Mosca
    www.thatlldoit.com
    http://tech.groups.yahoo.com/group/MS_Access_Professionals

    • Marked as answer by InnVis Monday, August 21, 2017 4:56 PM
    Monday, August 21, 2017 2:35 PM
  • Hi Alex,

    If you end up using the KeyDown or KeyPress event, this web page might come in handy.

    Hope it helps...

    Monday, August 21, 2017 3:00 PM
  • Excellent, thank you. It works almost flawlessly, but the key I'm using constantly scrolls through the controls. Is there anyway to make the key's original action be eliminated and only do as I tell it to do? Here's the code I'm using.

    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Dim X As Integer
    For X = 1 To 75
    
        Select Case KeyCode
            Case vbKeyLeft:
                If Me.Controls("sub" & X).Form.tglMove = True And Me.Controls("sub" & X).Left > 24 Then
                Me.Controls("sub" & X).Left = Me.Controls("sub" & X).Left - 24
                End If
    '       Case Else
        End Select
    Next
    
    End Sub

    Monday, August 21, 2017 3:16 PM
  • Hi,

    To cancel or ignore the normal behavior for the key pressed, you can set KeyCode to zero. For example:

    KeyCode=0

    Hope it helps...

    Monday, August 21, 2017 3:47 PM
  • Not working. It appears that when I click on the toggle button it sets focus on the subform and not the main form where the KeyDown code is written.... So I am forced to click the toggle button THEN the main form in order for it to work... Should I just write a setfocus on the toggle of the button or is there a better way?
    Monday, August 21, 2017 4:36 PM
  • Hi,

    There's lots of ways to possibly handle this. Have you tried sending the focus back to the main form when you click on the button? For example:

    Me.Parent.ControlName.SetFocus

    Hope it helps...

    • Marked as answer by InnVis Monday, August 21, 2017 4:55 PM
    Monday, August 21, 2017 4:50 PM
  • Yup. This is what I ended up doing and it worked perfectly. I actually made all objects in the main form Tab Stop NO and created an invisible and very tiny textbox named txtLooseFocus. I make that textbox grab focus every time I click the toggle button or leave the edit form.

    EDIT: Now my new concern is printing options, LOL.

    • Edited by InnVis Monday, August 21, 2017 4:55 PM
    Monday, August 21, 2017 4:55 PM
  • Hi,

    Small battles at a time. Cheers!

    Monday, August 21, 2017 6:26 PM