Results 1 to 11 of 11
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    2,097

    AfterUpdate event does not fire until focus moved to another control

    I an app with the following control:


    Click image for larger version. 

Name:	000.jpg 
Views:	24 
Size:	71.4 KB 
ID:	24148

    The AfterUpdate event code is:
    Code:
    Private Sub tbCellPhone_AfterUpdate()
    If Not IsNull(Me.tbCellPhone) Then Me.tbCellPhone = FmtPhoneNos(Me.tbCellPhone)
    End Sub

    The event does not fire after data is entered into the filed and Enter is pressed. The event fires AFTER I click on another filed. I can't even get the AfterEnter to fire either.

    What would cause the delay? (I have 2 other apps that are structured in exactly the same way and the AfterUpdate event fires exactly as expected.)

  2. #2
    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 GraeagleBill View Post
    I can't even get the AfterEnter to fire either.
    Not really surprised, as to my knowledge, at least thru 2007 (and certainly not in 2003) there is no 'AfterEnter' event!

    A Control's AfterUpdate event is not going fire until data is entered or changed in the Control, and the user either moves to another Control, closes the Form or closes Access itself. Simply hitting <Enter> won't, in and of itself, won't cause it to fire...unless...you have the Move After Enter option, for your installation of Access, set to Next Field or Next Record. It sounds as if it's set to Don't Move in the installation of Access you're currently using. That's the first thing I'd check. Don't remember exactly where to find that option in 2003, but in 2007 it's in Options - Advanced - Editing, and should be similar in 2003.

    Linq ;0)>

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    2,097
    Linq,
    We must have some sort of misunderstanding about what I was trying to explain, as I have several counter-examples to what you're saying. Certainly about A2003 not having an OnEnter event for text box properties.
    I'll do some tests in the AM to see if my db is either corrupted or getting confused with multiple forms where telephone numbers can be entered. Like maybe more than one text box with the same name but in different forms. The controls collection maybe corrupted?
    Bill

  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
    When things go wonky corruption is always a possibility! Although we usually think of Forms or entire Databases when we speak of corruption, individual Controls, such as Textboxes, can and do become corrupted. The test and the fix are one and the same; deleting the Control then re-creating it! If it was corrupt, you've verified the fact and solved the problem! If not, you've only lost a minute or two!

    Linq ;0)>

  5. #5
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    Try using the ON EXIT property rather than the AFTER UPDATE property to call your function. or alternately using an input mask to set up your formatting rather than relying on the function to do it (I'm guessing that's what fmtPhoneNos is doing), unless fmtphonenos is also validating length of the phone number etc as well.


    Can you show the code for your function?

  6. #6
    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
    AfterUpdate is the appropriate event for this kind of thing, but it only fires

    Quote Originally Posted by Access Help
    after changed data in a control or record is updated
    and despite the OP saying

    Quote Originally Posted by GraeagleBill
    I have 2 other apps that are structured in exactly the same way and the AfterUpdate event fires exactly as expected
    unless code is in place to Call the AfterUpdate event (using the Control's KeyDown event and trapping the <Enter> key...and GraeagleBill hasn't mentioned such) the AfterUpdate event will not fire on a Textbox until focus moves elsewhere! How could it? Until you leave the Control, Access doesn't know that you are thru entering data and ready to save the input!

    OnExit would work, of course, but firing his code before actually exiting the Textbox was his concern here. Also, not that it's a big point, but using OnExit would mean that the code would execute anytime the user tabbed thru the Control, instead of only when data had been entered/changed.

    Linq ;0)>

  7. #7
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    2,097
    Finally! The troublesome front-end db has been around for many years and I failed to notice the "Enter Key Behavior" for text boxes defaulted to "New line in field". Thus, when a string was entered and the enter key pressed the cursor continued to blink but was actually blinking on the "next line". Obviously, if the control's height can't grow beyond "one line" then one cannot observe what's happening. The A2003 Enter key default is move to next field in the tab sequence. Once I set the "Enter Key Behavior" for the offending tb controls to "Default" then the issue cleared up.

    rpeare's post mentioned the use of function "FmtPhoneNos" versus perhaps the use of an input mask. The function operates on phone numbers taking into account the apps regional settings with respect to the installations default area code. In the current installation, the default area code is for north-east California, 530. In the case of area code 530, there are 639 valid prefixes among all the landlines and cell phones. If the user enters a string from which the function can isolate 7 discrete digits, the user is informed as to what type of phone relates to the first 3 digits and the nominal city to which it pertains. If defaulting to area code 530 is acceptable, the string is formatted to "(530) nnn-nnnn". Otherwise, the user can change the area code as appropriate. If the function can isolate 10 discrete digits, then the area code is taken to have been included in the string and any user interaction is avoided.

  8. #8
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    2,097
    Sorry Linq, I meant "OnEnter" event.

    Click image for larger version. 

Name:	000.jpg 
Views:	12 
Size:	85.6 KB 
ID:	24151

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    For the record, the On Enter event is when focus arrives at the control, not when Enter is pressed while making an entry in it. From Help:

    When you move the focus to a control on a form (for example, by opening a form that contains one or more active controls, or by moving the focus to another control on the same form), the Enter and GotFocus events occur in this order:



    Enter GotFocus

    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    2,097
    Hi paul,
    Thanks for that little lesson. I don't recall ever having had the occasion to use the OnEnter event and my assumption about how it would be used was totally misconceived.
    Thanks,
    Bill

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    No problem Bill. I looked for you at Applebee's yesterday.
    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. Combo Box On Click Event does not fire
    By GraeagleBill in forum Forms
    Replies: 7
    Last Post: 10-30-2015, 01:20 PM
  2. Replies: 3
    Last Post: 07-22-2015, 04:37 PM
  3. Fire off event on another form
    By Ruegen in forum Access
    Replies: 4
    Last Post: 04-12-2015, 11:50 PM
  4. Replies: 11
    Last Post: 11-13-2014, 08:52 PM
  5. User focus control in AfterUpdate event
    By nosliwmada@gmailcom in forum Programming
    Replies: 3
    Last Post: 12-20-2010, 12:51 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