Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    athyeh is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2013
    Posts
    170

    Trying to SetFocus on a Textbox but it goes to the one above it?!

    Hi Folks,

    I have the following VBA code:

    Private Sub CheckIn_AfterUpdate()
    DoCmd.SetWarnings (False)
    DoCmd.OpenQuery "qryRecByExcUpd"


    Me.CheckIn = ""
    Me.CheckIn.SetFocus
    End Sub

    But for some reason after the code is done running the cursor lands on the textbox ontop of CheckIn... Can someone please help me troubleshoot?

    Thanks!

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    If it is not throwing an error and it is not setting focus on the control I will guess the code is not being executed.

    What happens if you comment out
    DoCmd.OpenQuery "qryRecByExcUpd"

  3. #3
    athyeh is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2013
    Posts
    170
    The code is being executed except for the last "Me.CheckIn.setFocus"

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Try commenting out the docmd. I edited my post after I read the thread a second time.

  5. #5
    athyeh is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2013
    Posts
    170
    Quote Originally Posted by ItsMe View Post
    Try commenting out the docmd. I edited my post after I read the thread a second time.
    Same thing :-/

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Then I will go out on a limb and say the event is not firing. Can you think of a way to test if the AfterUpdate event is firing?

    Also you should turn warnings back on when finished.
    DoCmd.SetWarnings true

  7. #7
    athyeh is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2013
    Posts
    170
    Quote Originally Posted by ItsMe View Post
    Then I will go out on a limb and say the event is not firing. Can you think of a way to test if the AfterUpdate event is firing?

    Also you should turn warnings back on when finished.
    DoCmd.SetWarnings true

    Yep, So I turned SetWarnings on, It prompts me to update the record (the query is an update query), it updates the query, it clears the textbox "CheckIn", it does everything except the last part, SetFocus on itself.

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    What I meant was after you set warnings to false, don't forget to turn warnings back on. But we do know the code is firing now....

    So we probably need to take focus off of the query object. I would have expected a run time exception when the control was not available but try....

    Forms!FormName.CheckIn.SetFocus

    You will need to put the name of the form in place of FormName

  9. #9
    IslandHydro is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2013
    Location
    Whidbey Island, Washington State, USA
    Posts
    21
    Try doing two set focus'
    first set focus to the form
    then set focus to the object

  10. #10
    athyeh is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2013
    Posts
    170
    Thank you for your replies, but neither option is working...

  11. #11
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    The Access Gnomes can be quirky! You cannot set Focus to a Control from an event in that Control. And you cannot set Focus to a Form if there is a single Control on that Form that can receive Focus.

    So set Focus to any other Control and then set it back on CheckIn.

    BTW, the only event of a Control that will leave the Focus on that Control is the Control's BeforeUpdate event, if you use

    Cancel = True.

    Linq ;0)>

  12. #12
    athyeh is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2013
    Posts
    170
    Quote Originally Posted by Missinglinq View Post
    The Access Gnomes can be quirky! You cannot set Focus to a Control from an event in that Control. And you cannot set Focus to a Form if there is a single Control on that Form that can receive Focus.

    So set Focus to any other Control and then set it back on CheckIn.

    BTW, the only event of a Control that will leave the Focus on that Control is the Control's BeforeUpdate event, if you use

    Cancel = True.

    Linq ;0)>
    WOW!~ THANK YOU! YOU ARE INCREDIBLE! WOOSA!

    Thank you all for your replies and help.

    Thread Solved.

  13. #13
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Well, the code is executing. You can not see it because the query object is open. Let's try another aproach. Why are you opening the query object if you do not want to have focus on it? Is this an action query?

    If all you want to do is run an action query you can
    Code:
    CurrentDb.Execute "qryRecByExcUpd"
    Me.CheckIn.SetFocus
    Me.CheckIn = ""

  14. #14
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I did not notice the control name was the same as the event handler. Thanks Linq

  15. #15
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by ItsMe View Post
    I did not notice the control name was the same as the event handler. Thanks Linq
    No problem! Between answering questions, here, you probably do something frivolous, like working for a living, while I just sit around all day, lurking in Access forums!

    Linq ;0)>

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Proper Use of SetFocus?
    By rpeare in forum Forms
    Replies: 14
    Last Post: 10-21-2013, 02:58 PM
  2. Requirements for SetFocus
    By EddieN1 in forum Forms
    Replies: 2
    Last Post: 09-01-2013, 06:19 PM
  3. setfocus on an textbox different way
    By white_flag in forum Access
    Replies: 0
    Last Post: 09-21-2011, 05:04 AM
  4. setfocus on an textbox
    By white_flag in forum Access
    Replies: 2
    Last Post: 09-21-2011, 04:16 AM
  5. SetFocus Problem
    By ColPat in forum Programming
    Replies: 2
    Last Post: 06-21-2010, 04:43 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