Results 1 to 6 of 6
  1. #1
    kagoodwin13 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Feb 2012
    Posts
    181

    Click away from textbox or combobox when executing Save command

    I've done a lot of Google searching, and this problem seems to be common, but too vaguely worded to find a solution.



    I have an unbound form that has several fields, and a save button that updates the desired table and fields.

    The problem I am running into is that when the save button is clicked, the last edited textbox or combobox is still "being edited," and is in that phase until I click somewhere else on the form. After updating AND clicking, the new value is stored in the textbox/combobox.

    Is there a way to programmatically click away to somewhere else, which would in effect save the value of the last edited field?

    Thanks!

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    Really? I haven't seen that behavior. Clicking on the button should "save" the textbox, since focus has left it. I just tested and the after update event of a textbox fired when I clicked on a button, then the button click code. Can you post a db that exhibits this problem?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by kagoodwin13 View Post
    ...the last edited textbox or combobox is still "being edited,"...
    When a control loses focus it will already be updated. In other words, the AfterUpdate event has already committed the Text property to the Value property. If a textbox control loses focuses after the text propert has changed, the Form's Dirty property will = True.
    KeyDown > BeforeUpdate > AfterUpdate > Exit > LostFocus

    https://support.office.com/en-in/art...86553682f9#bm4

  4. #4
    kagoodwin13 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Feb 2012
    Posts
    181
    I was able to solve it, but it doesn't really make much sense to me. Upon pressing the save image, I changed focus to another combobox in the form that can't be edited.

    The purpose was to save the value in txProjectNotes. The problem was that after being edited, txProjectNotes would not lose focus, the focus was stuck on the textbox, even if the save image was clicked. That meant as a result, that if a new value was typed into txProjectNotes, it wasn't stored before the save image was clicked.

    It may have something to do with the fact that the textbox Enter Key Behavior was changed to New Line In Field. It may also be that images behave differently than command buttons with concern to focus.

    I tried to change focus to another textbox that is hidden, but Access wouldn't allow that. I guess that makes sense - can't focus on a hidden field.

    Working code:

    Code:
    'Click away from editable fields to save values
    Me.cmCustomerName.SetFocus
    'Run update command
    strUpdate = "UPDATE tProject SET tProject.ProjectNotes = '" & Me.[txProjectNotes].value & "' WHERE tProject.ProjectName = '" & Me.[cmProjectName].value & "'"
    DoCmd.RunSQL strUpdate

  5. #5
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by kagoodwin13 View Post
    ...Enter Key Behavior was changed to New Line In Field...
    That could be something. Adding data validation and using variables might help to pinpoint the cause.

  6. #6
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    You said save "button" in the first post, save "image" in the second. If you're using an image for a button, it could be that an image can't have focus and thus focus doesn't leave the textbox, so I think this is your issue:

    Quote Originally Posted by kagoodwin13 View Post
    It may also be that images behave differently than command buttons with concern to focus.
    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. Replies: 1
    Last Post: 02-01-2015, 12:16 AM
  2. Click on Locked Textbox
    By bginhb in forum Forms
    Replies: 2
    Last Post: 12-22-2011, 11:19 AM
  3. On click textbox inserts value back on combobox
    By whitelockben in forum Forms
    Replies: 2
    Last Post: 10-09-2011, 05:23 AM
  4. "There was an error executing this command"
    By rnichols86 in forum Access
    Replies: 16
    Last Post: 11-18-2009, 06:56 PM
  5. Replies: 0
    Last Post: 09-11-2006, 07:11 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