Results 1 to 15 of 15
  1. #1
    bginhb is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    May 2011
    Location
    Huntington Beach, CA, USA
    Posts
    47

    How to force an update

    I have a form that displays/updates multiple records. One field in the record keeps track of hours but is restricted to hours and quarter hours. As part of the implementation the User is permitted to update the field for hours and an unbound combobox containing quarter hour plus and minus values - i.e. -0.75, -0.50 ... +0.50 is being used to micro adjust the hours field. The form also totals the hours field using a textbox in the form header using a domain aggregate.



    Since the hours field is not being updated by User data entry the "dirty" property is not triggered and I am at a loss to figure out how to trigger a field update so the summary hours textbox will update.

    Appreciate any assistance ... Thnx.
    Last edited by bginhb; 06-30-2011 at 09:22 AM. Reason: clarity

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You can update the control from any other control in code.

  3. #3
    bginhb is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    May 2011
    Location
    Huntington Beach, CA, USA
    Posts
    47
    Thanks RuralGuy but I don't see how that solves the problem.

    The summary control is a textbox that uses a domain aggregate (Dsum) to add the values of all the hours fields. The combobox is used to add or subtract 1/4 hours from the value of the Hours field and I want the resulting hours amount to be immediately summarized in the summary control. I don't know how to achieve that without finding a way to trigger an update to the hours field so that a requery to the summary control will produce the correct total.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Me.YourTextBox.Refresh(or Recalc) should do it.

  5. #5
    bginhb is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    May 2011
    Location
    Huntington Beach, CA, USA
    Posts
    47
    I'm afraid it doesn't.
    If I understand correctly a refresh of a bound textbox will merely refresh the box to the value in the underlying table. That's the opposite of what I need to achieve.

    I need to have the value of the textbox updated into the underlying table so that a refresh of the summary total box (using Dsum) will be able to sync with the screen that shows an updated value that was created using the combobox.

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Have you tried a Me.Recalc which will Recalc the entire form?

  7. #7
    bginhb is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    May 2011
    Location
    Huntington Beach, CA, USA
    Posts
    47
    I have but this is a problem at the record level. How to get Access to update a record without leaving the record.

    What I do to get this to work after a manual entry to a bound control is to code the AfterUpdate event "If Me.Dirty Then Me.Dirty = False". Setting Me.Dirty to False causes the current record to update to the values in the form controls without having to leave the record. So I learned from Bob Larson the other day.

    But when I use a control (combobox in this case) to make additions or subtractions to a bound control the Dirty Event is not triggered and setting it to false as indicated above, does not trigger an update. The combobox solution is quite elegant from an interface point of view so I'm reluctant to let it go and I'm looking for an alternative way to get access to save the data in the controls to the underlying table/query without leaving the current record.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Is this what you're after?

    DoCmd.RunCommand acCmdSaveRecord

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

  9. #9
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    In addition to Paul's suggestion, I also believe Me.Dirty = False will save the current record without regard to the current value of Dirty.

  10. #10
    bginhb is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    May 2011
    Location
    Huntington Beach, CA, USA
    Posts
    47
    Thanks folks,
    I tried using me.dirty = false and could not get it to work ... that's what began this current thread, but I may have overlooked something so I'll check it again.
    If that doesn't work I'll try the DoCmd alternative.
    Thank you both!

  11. #11
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    The difference between

    If Me.Dirty Then Me.Dirty = False

    And

    DoCmd.RunCommand acCmdSaveRecord

    is that the first one will only run if a bound field is changed. The second will attempt a save regardless. So the second may be what you need.

  12. #12
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Bob,
    I believe my comment in Post #9 is valid as well. It does not test the Dirty property.

  13. #13
    bginhb is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    May 2011
    Location
    Huntington Beach, CA, USA
    Posts
    47
    Apparently me.dirty=false does work and I made another error that caused me to believe it didn't.

    Sorry for troubling you folks but thanks so much for helping resolve my problem.

  14. #14
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Thanks for posting back with your success.

  15. #15
    corrie is offline Novice
    Windows 8 Access 2013
    Join Date
    Oct 2015
    Posts
    8
    I just have to say that my problem had zero, zilch, nothing to do with this rather old discussion, but between the various comments a major schlepp for this old man was resolved.
    I've kinda lost the ability to remember all the syntax, but the logic's still fine. Need some reminders though.
    Thanks!

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

Similar Threads

  1. Force users to log off
    By Bruce in forum Security
    Replies: 8
    Last Post: 01-10-2013, 07:03 PM
  2. Force numeric value
    By jgelpi16 in forum Programming
    Replies: 5
    Last Post: 01-24-2011, 12:37 PM
  3. Replies: 10
    Last Post: 11-12-2010, 05:17 PM
  4. A way to force Access to update external file?
    By gkun in forum Import/Export Data
    Replies: 0
    Last Post: 10-27-2009, 06:11 PM
  5. Force writing from the right in a field?
    By Looping in forum Forms
    Replies: 0
    Last Post: 01-23-2006, 03:03 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