Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2010
    Posts
    2

    User focus control in AfterUpdate event

    I have a form that has six textboxes:
    txtUserName
    txtOrderNum
    txtAccountNum
    txtAccountNum2


    txtItemNum
    txtQuantity

    Each of these textboxes are user-editable and all of them use the "BeforeUpdate" to implement validation. All of that works well.

    In addition, in the "AfterUpdate" event of the "txtOrderNum" textbox I have logic to look up the AccountNum and AccountNum2 from a linked table and populate the corresponding textboxes "txtAccountNum" and "txtAccountNum2". To set the values in these textboxes I have to use the code:

    txtAccountNum.SetFocus
    txtAccountNum.Value = strAccountNum

    txtAccountNum2.SetFocus
    txtAccountNum2.Value = strAccountNum2

    All of this logic is also working properly.

    The "AfterUpdate" event is firing essentially when the user tabs to or clicks on another control. The problem that I'm having is that when I set the focus to the "txtAccountNum" and "txtAccountNum2" controls to set these values I don't have the knowledge of what the user clicked on after updating the "txtOrderNum" control. As an example:

    User enters a value in "txtOrderNum", then clicks on the "txtItemNum" field.
    Before the focus goes to the "txtItemNum" field, the "txtOrderNum" event "AfterUpdate" fires.

    The code grabs the values from the linked table; sets the focus to "txtAccountNum" and sets its value, then set the focus to "txtAccountNum2" and sets its value.

    At this point the focus is on "txtAccountNum2", where I want it to be on the "txtItemNum" because that is what the user clicked on.

    Any thoughts or ideas are appreciated.

    Here is a dummied-down version of the code:

    Private Sub txtOrderNum_AfterUpdate()
    Me.txtAccountNum.SetFocus
    Me.txtAccountNum.Value = "12354"
    Me.txtAccountNum2.SetFocus
    Me.txtAccountNum2.Value = "56789"
    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Try simply dropping the two SetFocus lines. They are not necessary (they would be if you used the .Text property, which you haven't).
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Join Date
    Dec 2010
    Posts
    2
    That did the trick! Thank you pbaldy!

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help, and welcome to the site by the way!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. AfterUpdate event won't refresh subform!
    By Remster in forum Forms
    Replies: 16
    Last Post: 11-26-2010, 10:06 AM
  2. AfterUpdate not updating
    By P5C768 in forum Programming
    Replies: 6
    Last Post: 06-10-2010, 02:31 PM
  3. Replies: 1
    Last Post: 10-19-2009, 02:37 AM
  4. Maintaining Control Focus
    By sabbo64 in forum Programming
    Replies: 3
    Last Post: 08-18-2009, 11:56 AM
  5. Replies: 1
    Last Post: 12-21-2005, 12:27 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums