Results 1 to 10 of 10
  1. #1
    tylerg11 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2011
    Posts
    200

    Position cursor at the end of the textbox after AfterUpdate property

    I am using an unbound textbox at the top of my form for filtering purposes. The user types in a string and hits "Tab" which kicks of the filter which is defined in the AfterUpdate property. I want the focus to return to the same textbox and position the curosor after the last character. I am trying to use SelStart but not having success.



    Code:
        Me.Filter = "COURSE_NAME Like '*" & Me.txtFilter & "*'"
        Me.FilterOn = True
        txtFilter.SetFocus
        txtFilter.SelStart = txtFilter.SelLength

  2. #2
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Change the last line to
    Code:
        txtFilter.SelStart = len(Me.txtFilter)

  3. #3
    tylerg11 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2011
    Posts
    200
    Quote Originally Posted by Dal Jeanis View Post
    Change the last line to
    Code:
        txtFilter.SelStart = len(Me.txtFilter)
    That didn't work either. Still keeps the cursor at the front. See below.

    Click image for larger version. 

Name:	10-7-2013 1-31-01 PM.jpg 
Views:	13 
Size:	4.2 KB 
ID:	13993

  4. #4
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    okay, try this
    Code:
    Me.txtFilter.SetFocus
    Me.txtFilter.SelStart = len(Me.txtFilter.Text)
    That shouldn't work, but random debugging actions are occasionally better than inaction.
    Last edited by Dal Jeanis; 10-07-2013 at 01:09 PM. Reason: added Me. for additional clarity

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Try putting that last line in txtFilter GotFocus event (without Text property).
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    tylerg11 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2011
    Posts
    200
    Quote Originally Posted by Dal Jeanis View Post
    okay, try this
    Code:
    Me.txtFilter.SetFocus
    Me.txtFilter.SelStart = len(Me.txtFilter.Text)
    That shouldn't work, but random debugging actions are occasionally better than inaction.
    Same result. I have been trying different things but still getting the same result. Thanks anyway.

  7. #7
    tylerg11 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2011
    Posts
    200
    Quote Originally Posted by June7 View Post
    Try putting that last line in txtFilter GotFocus event (without Text property).
    Tried this too and no luck.

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Code works for me. If you want to provide db for analysis, follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Okay, then I'm betting you have a timing problem. Try a time-waster before the setfocus command. Just do a 1000 rep do loop.

  10. #10
    sneuberg is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Sep 2014
    Posts
    23

    You can't get here from here

    For reasons unknown you can't directly set focus in an afterupdate to the control that triggered the afterupdate event. As a work around you can set the focus to some other control and then to the control that fired the event, e.g.,

    Me.SomeOtherControl.SetFocus 'Hopeful you have one that's visible
    Me.txtFilter.SetFocus

    This work around could mess up other things. For example if txtFilter has focus and has been updated (changed) and you click on a button the focus will end up on txtFilter but the buttons code will not be executed. You get sticky buttons. You have to click them twice.

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

Similar Threads

  1. Replies: 9
    Last Post: 10-04-2013, 11:48 AM
  2. Replies: 10
    Last Post: 03-29-2012, 10:44 AM
  3. T-SQL Cursor within a cursor
    By allenjasonbrown@gmail.com in forum Programming
    Replies: 6
    Last Post: 04-14-2011, 12:31 PM
  4. Bold Field by Cursor Position
    By Rawb in forum Forms
    Replies: 4
    Last Post: 02-08-2011, 08:03 AM
  5. Replies: 1
    Last Post: 08-10-2008, 01:09 AM

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