Results 1 to 4 of 4
  1. #1
    ScottXe is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Aug 2012
    Posts
    25

    Set the control in focus

    I tried to set the focus in the previous control "txtAdd" without success. Can someone advise me why it does not work in the after update event of txtAdd control in the attached demo file. Thanks!
    Attached Files Attached Files

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Quote Originally Posted by ScottXe View Post
    I tried to set the focus in the previous control "txtAdd" without success. Can someone advise me why it does not work in the after update event of txtAdd control in the attached demo file. Thanks!
    Can't explain why it doesn't work but if you put your code in the Got Focus of the next control ( txtModel ) it seems to work.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    ScottXe is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Aug 2012
    Posts
    25
    Quote Originally Posted by Bob Fitz View Post
    Can't explain why it doesn't work but if you put your code in the Got Focus of the next control ( txtModel ) it seems to work.
    Hi Bob,

    It works after I place the set focus statement into Got Focus of txtModel control. Never thought this way to resolve it. Thanks a lot.

  4. #4
    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 ScottXe View Post

    I tried to set the focus in the previous control "txtAdd" without success. Can someone advise me why it does not work in the after update event of txtAdd control
    This is just one of those Access quirks! To get Focus to stay in a Control, if some validation on the entered data fails, you have to use the Control's BeforeUpdate event, and set Cancel = True. This stops the update of the Field and leaves Focus in the Control.

    Code:
    Private Sub txtAdd_BeforeUpdate(Cancel As Integer)
      ' If Validation Code fails
      'Messagebox warning to user
      Cancel = True 
    End Sub

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

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

Similar Threads

  1. Tab Control Out of Focus - HELP!
    By derek7467 in forum Forms
    Replies: 2
    Last Post: 02-13-2014, 01:38 PM
  2. Focus in web browser control
    By bjornhe in forum Access
    Replies: 0
    Last Post: 10-27-2011, 05:10 AM
  3. Focus on Key Control
    By windwardmi in forum Access
    Replies: 1
    Last Post: 09-07-2011, 04:57 PM
  4. How to control a button when it has focus
    By shubhamgandhi in forum Programming
    Replies: 2
    Last Post: 07-28-2011, 03:18 PM
  5. Maintaining Control Focus
    By sabbo64 in forum Programming
    Replies: 3
    Last Post: 08-18-2009, 11:56 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