Results 1 to 4 of 4
  1. #1
    kleaverjr is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Apr 2022
    Posts
    53

    Should Exit Sub cause setfocus to change ?

    There is no practical way to copy all of the code that is involved with this problem as it's substantial and there are tons of references to multiple tables. As I have used debug.print I can find no reason why what is happening to occur.



    I have a situation where in some conditions, that the program exits the sub using EXIT SUB as the command. Just prior to the EXIT SUB command I have txtItemBarCode.setFocus. And the program does set the focus to the text box because I added a test line in the code and it looks like this:

    Code:
    
    txtItemBarCode.SetFocus
    txtItemBarCode.Text = "TEST"
    
    Exit Sub
    When I do a Step-By-Step through the program no other code is executed. But it is going to the next TabIndex and is setting the focus on that.

    Any ideas as to why this is happening. Again I'm sorry that I really can't include the other parts of the code,. though I don't know how that will help since the textbox is receiving the focus but loses it the moment it exits the sub?

    Thanks.

    Ken L

  2. #2
    Edgar is online now Competent Performer
    Windows 8 Access 2016
    Join Date
    Dec 2022
    Posts
    274
    Exit Sub terminates only the procedure where it appears, you have some other code making your textbox lose focus.

  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    May also depend on what sub/function you are using your setfocus code in - might be triggering the default form cycle behaviour

  4. #4
    kleaverjr is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Apr 2022
    Posts
    53
    Quote Originally Posted by CJ_London View Post
    May also depend on what sub/function you are using your setfocus code in - might be triggering the default form cycle behaviour
    I could never figure out what else could be triggering this problem. However, I found a "solution" though it bothers be this is more a stopgap measure not an actual fix. After I set focus, I also set the selstart property to zero as well (since the textbox is always blanked out after the enter key is entered and the text in the textbox is stored in a variable..The issue is not really resolved though.

    Thanks.

    Ken L

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

Similar Threads

  1. Replies: 21
    Last Post: 09-28-2021, 09:18 AM
  2. Replies: 15
    Last Post: 10-08-2015, 02:24 AM
  3. Requirements for SetFocus
    By EddieN1 in forum Forms
    Replies: 2
    Last Post: 09-01-2013, 06:19 PM
  4. VBA Code SetFocus
    By tweety in forum Programming
    Replies: 1
    Last Post: 03-26-2013, 12:51 PM
  5. Replies: 2
    Last Post: 12-20-2012, 03:06 PM

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