Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Star Lounger
    Join Date
    Aug 2002
    Location
    Des Moines, Iowa, USA
    Posts
    85
    Thanks
    0
    Thanked 0 Times in 0 Posts

    re:Making the enter key work on a UserForm (XP)

    Is there a way to make the enter key work in the same fashion as clikcing on an OK button in a UserForm? I have investigated the KeyPress event for the last input field on my UserForm, but can't seem to find the right combination to get it to work. Any help is greatly appreciated.

  2. #2
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: re:Making the enter key work on a UserForm (XP)

    If you set one of the button's Default property to true, it will react to an enter.
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  3. #3
    Star Lounger
    Join Date
    Aug 2002
    Location
    Des Moines, Iowa, USA
    Posts
    85
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: re:Making the enter key work on a UserForm (XP)

    Thank you for your quick response! You are correct, the Default property will make a button work with the enter key, but I want to know if it is possible to press enter after the last input field is filled, so the user does not have to stop keying, grab the mouse, and position it to the OK button, and click to process.
    I have discovered that if the OK button is the next tab after the last input field, the user can press enter twice to process the information. I'm thinking that is the closest I am going to get to keeping the user's hands on the keyboard. If there is an alternative way, I would be interested to know it.

  4. #4
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: re:Making the enter key work on a UserForm (XP)

    You can set the OK button as the Default and get them to use the Tab key to move from field to field. This is pretty standard on forms.
    Legare Coleman

  5. #5
    Star Lounger
    Join Date
    Aug 2002
    Location
    Des Moines, Iowa, USA
    Posts
    85
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: re:Making the enter key work on a UserForm (XP)

    Thanks for your response. I do have the Default property set on the OK button, and the tab from field to field works. I am wondering if there is an equivalent in Excel to the Access "On Enter" property for a text input field.

  6. #6
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: re:Making the enter key work on a UserForm (XP)

    Isn't that the "TextBox1_enter" event?
    Runs the code before it gets the focus (not after typing enter)?

    Steve

  7. #7
    Star Lounger
    Join Date
    Aug 2002
    Location
    Des Moines, Iowa, USA
    Posts
    85
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: re:Making the enter key work on a UserForm (XP)

    I think you are right. The enter event is fired prior to getting focus, which may answer my question. I currently have my OK button as the next tab after the last input field. By setting the btnOK_Enter event, pressing enter on the last input field would fire this event and process the information. I may have been barking up the wrong tree - I needed to look at a pre-set focus event for my OK button, instead of an after leaving event on my input field. I will try this. Thank you!!!

  8. #8
    Star Lounger
    Join Date
    Aug 2002
    Location
    Des Moines, Iowa, USA
    Posts
    85
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: re:Making the enter key work on a UserForm (XP)

    I tried using the btnOK_Enter event, and it worked perfectly! When pressing enter after the last input field, the program ran. This will make life much easier, as this project deals with a large amount of manual entry. Thanks again.

  9. #9
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: re:Making the enter key work on a UserForm (XP)

    I wouldn't be too pleased if I were a user. I often TAB through the controls on a dialog, e.g. just because I want to go back to change what I put in the first one and I'm on the (almost) last one. In your siituation this would OK me out of the dialog!

    I would stick to the behaviour that they need to enter the last entry and then can press enter or click OK to accept the form.
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  10. #10
    Star Lounger
    Join Date
    Aug 2002
    Location
    Des Moines, Iowa, USA
    Posts
    85
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: re:Making the enter key work on a UserForm (XP)

    If I were a user, I would be too. The users have the ability to tab between fields(the enter key works in the same fashion as the tab to move between fields). I wanted to add the ability for the user to keep his hands on the keyboard, and more quickly enter what may be hundreds of records. In order for this to happen, I needed to find an event that works in the same manner as the Access "On Enter" event. What I found in Excel is more like an "Upon Exit" event (event fires between the input field losing focus, and the OK button gaining focus). It has nothing to do with replacing a tab with an enter.

    Think of yourself as a user. If you had to add dozens, or possibly hundreds of rows of data (each row being checked as entered) and each time you finish one record, would you want to stop keying, grab the mouse, position the mouse to the OK button and click it, let the program validate the info, then input the next record, or press enter (or tab) after the last input field, let the program validate the info, and continue to the next record?

    The solution I used just says when the last input field loses focus (through tab or enter ), and control enters the OK button, to process the information on the UserForm. My intent was not to replace the tab key with the enter key. I apologize if I did not explain myself properly.

  11. #11
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: re:Making the enter key work on a UserForm (XP)

    I get your point. You didn't get all of mine <smile>. I too wish to avoid that mouse. As soon as the last entry has been entered, the focus goes to the OK button and pressing enter *again* will start the validation process and (if OK) the next entry. So Enter will OK the dialog, unless an entry is still being edited, TAB will OK the entry itself.
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  12. #12
    Star Lounger
    Join Date
    Aug 2002
    Location
    Des Moines, Iowa, USA
    Posts
    85
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: re:Making the enter key work on a UserForm (XP)

    I'm glad we're on the same page. I was able to find a way to save a keystroke in the routine though. By putting an Entry event on btnOK, the user only has to tab or enter out of the last input field, and the information is validated, thus eliminating the need to press Enter on the OK button (The entry event fires after focus is lost on the input field, but before focus is set on the OK button). It works really slick.

    Thanks for showing interest in this issue. I really appreciate the time you've devoted to this!

  13. #13
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: re:Making the enter key work on a UserForm (XP)

    I would agree.

    Users need a chance to review the info they have entered before clicking OK.

  14. #14
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: re:Making the enter key work on a UserForm (XP)

    A Userform in, say, Word or Excel, is very different than a Userform in Access.
    In Access the form is usually tied to a database, so their is a concept of "last" entry.
    In a typical Word or Excel Userform, no such concept exists.

  15. #15
    Star Lounger
    Join Date
    Aug 2002
    Location
    Des Moines, Iowa, USA
    Posts
    85
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: re:Making the enter key work on a UserForm (XP)

    The functionality of the UserForm is no different than when you password protect a worksheet. In protecting a worksheet, you are prompted for the password, which, when entered, you can press enter or click on the OK button. That was the type of functionality I was looking for, and implemented in my UserForm.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •