Error 2166 - how do I clear 'unsaved changes'?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Deekay
    New Member
    • May 2010
    • 21

    #1

    Error 2166 - how do I clear 'unsaved changes'?

    I have an unbound single record form (Access 2003) that is used as a container to collect user input (name, usergroup and dates) through combos bound to three different tables. A button then processes a number of SQLs statements to add records to yet another table. This is to be distributed to non-expert users. In order to avoid processing before all the data has been entered correctly, I have locked controls and then progressively unlocked them as the user works through the form.

    All works OK, except that....

    I am expecting that the user will want to process several 'names' one after the other, so at the final stage, when my code displays a confirmatory message that the records have been added and the user clicks 'OK', I want to reset the form back to its initial state. However when the code re-runs the routine to lock the controls it returns error 2166, 'control cannot be locked whilst there are unsaved changes'.

    What I think is happening (but correct me if you know different) is that because the form is unbound and the processing is a piece of SQL, the information is still being held in each of the controls and is not being be 'cleared' or 'saved' in the normal way by moving to a new record as would happen on bound form.

    I have tried resetting the controls to Null, Nothing, Empty and "" immediately before locking without success - also 'docmd.runcomma nd accmdsave' and refresh.

    Any ideas about how to reset this unbound form back to its initial state programmaticall y without the bother of closing it and re-opening it each time?
  • Oralloy
    Recognized Expert Contributor
    • Jun 2010
    • 988

    #2
    Try something like this, which is the Access "Undo" menu option?
    Code:
        DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
    Either that, or there are dirty bits that you might be able to reset.

    Good Luck!

    Comment

    • Deekay
      New Member
      • May 2010
      • 21

      #3
      Thanks Oralloy for your suggestion, but it didn't solve the problem.
      I searched a number of forums to see if other people have had this problem with 'unsaved changes' blocking changes to proerties and whilst it's mentioned I haven't seen a solution.

      Comment

      Working...