Results 1 to 8 of 8
  1. #1
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Dallas, Texas, USA
    Posts
    1,680
    Thanks
    0
    Thanked 1 Time in 1 Post

    Coded 'ENTER' key?(Win98 / XL10)

    A trivial issue, I'm sure, but I'm trying to keep things user-friendly.

    At the bottom of a User-Form there is a "FINISH" button which closes the form and writes info from text boxes to a database.

    If the user types data into a textbox and immediately clicks on the "FINISH" button, the data is not posting to the database - the user is required to press the "ENTER" key before clicking "FINISH". In other words, you can't just type data into the box and just leave the cursor in the box, that entry will never make it!

    Is it wise to code an "ENTER" key press into the code? - afterall, the user will surely assume that if he typed data into a textbox it would post. IF he doesn't want to post the data, there is always a "CANCEL" button to use a the bottom of the form.
    - Ricky

  2. #2
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Coded 'ENTER' key?(Win98 / XL10)

    He should never have to press the Enter key. For example, a fast typist will probably want to use the Tab key and Shift Tab to navigate the form. Use the lost focus event to replace the Enter key. --Sam
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  3. #3
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Dallas, Texas, USA
    Posts
    1,680
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Coded 'ENTER' key?(Win98 / XL10)

    Sam - You're exactly right. Looking at my project, there are a dozen text boxes on the form and the tab order is set properly so the tab key will navigate. I even have the FINISH & CANCEL buttons set up with accelerator keys.

    However, there remains a probability that the user would leave the cursor inside that last text box thinking that the FINISH button will pick it up. The user must get out of that box before the entry will "take".

    What's the best way to help the user in this case?
    - Ricky

  4. #4
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Coded 'ENTER' key?(Win98 / XL10)

    When the user enters the text box disable the FINISH button by way of the GotFocus event of that button, and use the LostFocus event to renable the FINISH button.

    Andrew

  5. #5
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Coded 'ENTER' key?(Win98 / XL10)

    Pusing the finish button causes a lost focus event on the last field. You may want a DoEvents in the buttonPush event in case it fires first, but I don't think it will. HTH --Sam
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  6. #6
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Dallas, Texas, USA
    Posts
    1,680
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Coded 'ENTER' key?(Win98 / XL10)

    An excerpt:

    Private Sub ComFinish_Click()

    Application.ScreenUpdating = False
    Dim EditRow As Integer
    EditRow = Range("EditRow").Value - 0
    Sheets("Database").Select
    Range("b1").Select

    ActiveCell.Offset(EditRow, 0).Value = Val(TxtBoxCustCt)
    ActiveCell.Offset(EditRow, 1).Value = Val(TxtBoxNet)
    .......
    Should the first line in this routine be a simple statement that sets FOCUS to the FINISH button? That way, no matter where the user left the cursor, the FINISH button would move it so that all entries were "locked" into their boxes.
    - Ricky

  7. #7
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Dallas, Texas, USA
    Posts
    1,680
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Coded 'ENTER' key?(Win98 / XL10)

    I've added the line "ComFinish.SetFocus" to the FINISH button routine as indicated below. I've tested it and it appears to work great.

    There's usually a drawback or consequence to simple fixes - do you how this might cause a problem?

    Private Sub ComFinish_Click()

    ComFinish.SetFocus
    Application.ScreenUpdating = False
    Dim EditRow As Integer
    EditRow = Range("EditRow").Value - 0
    Sheets("Database").Select
    Range("b1").Select

    ActiveCell.Offset(EditRow, 0).Value = Val(TxtBoxCustCt)
    ActiveCell.Offset(EditRow, 1).Value = Val(TxtBoxNet)
    - Ricky

  8. #8
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Coded 'ENTER' key?(Win98 / XL10)

    After all of my ravings, I fired up XL and tried it myself. Discovered that in XL9 there is no lost focus event, but the afterupdate event seems to do the trick. However, it appears from your responses that XL10 has a lostFocus event. Anyway, i don't think that ComFinish.SetFocus does anything because the focus is already there. Put a line debug.print "xxx fired" at the begining of each event routine and you can see the sequence of events in the immediate window.
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

Posting Permissions

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