How to stop subforms from autosaving upon losing focus?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Keriana30
    New Member
    • Nov 2007
    • 7

    How to stop subforms from autosaving upon losing focus?

    I have a Main form with several tabs. Each tab contains subforms that hold various employee information regarding benefits, dependant coverage, retirement, etc. I have a Save and cancel function on the form. I wish to edit information on these tabs regarding employee information and wait until save is clicked to save all information. If the user selects cancel I'd like it to cancel all changes made to all subform and form fields. However the subforms are saving changes automatically and when I attempt a Cancel = true in the before_update event it refuses to allow that subform to lose focus until the chgs are saved. I can populate the fields programatically and force updates and cancels but...some of the subforms are datagrids for 1 to many relationships and variable arrays have to be declared with constant expressions. I would appreciate any suggestions on this.

    Thanks, Keriana
  • puppydogbuddy
    Recognized Expert Top Contributor
    • May 2007
    • 1923

    #2
    Originally posted by Keriana30
    I have a Main form with several tabs. Each tab contains subforms that hold various employee information regarding benefits, dependant coverage, retirement, etc. I have a Save and cancel function on the form. I wish to edit information on these tabs regarding employee information and wait until save is clicked to save all information. If the user selects cancel I'd like it to cancel all changes made to all subform and form fields. However the subforms are saving changes automatically and when I attempt a Cancel = true in the before_update event it refuses to allow that subform to lose focus until the chgs are saved. I can populate the fields programatically and force updates and cancels but...some of the subforms are datagrids for 1 to many relationships and variable arrays have to be declared with constant expressions. I would appreciate any suggestions on this.

    Thanks, Keriana
    put the following code after the cancel = true statement and see if it helps. If not, then you need to post your code.

    Code:
    If Me.Dirty = True
      Me.Undo
    End If

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32633

      #3
      I guess from the
      Originally posted by Keriana30
      ...some of the subforms are datagrids for 1 to many relationships.. .
      bit that the recordsource for all the subforms cannot be simply the same. In which case then, Access will not be able to manage this as you envisage it. Each form is only active when it has the focus and will either update or cancel (lose changes) when focus is lost.
      pDog has already indicated the code you need if you want to move on and lose any changes.
      How reasonable it is to expect Access to maintain links to various recordsets (many of which are inter-dependant) is another matter.
      I imagine that this could be done (but with great difficulty and having to recode many of the built-in features of Access) but I doubt it's worth the effort. It would essentially be coding around Access rather than coding within it, which should be avoided where possible.

      Comment

      • MMcCarthy
        Recognized Expert MVP
        • Aug 2006
        • 14387

        #4
        The only way to handle subforms in this manner is to use PuppyDogBuddy's me.dirty routine on all the subforms. Of course you would have to refer to the subform.

        Me.subformobjec tname.Form.Dirt y

        However, you will have a problem with the datagrids if you changed anything other than the current record. If you move off the current record then any changes will be saved.

        My advice is to have a save and cancel button on each of the subforms. This will at least allow you to control the current record.

        Mary

        Comment

        • Keriana30
          New Member
          • Nov 2007
          • 7

          #5
          Yeah. I would much rather be using something like VB unfortunately it is not an option at work. The idea was to make changes to any of their information and save one time but I cannot do from one recordsource because of the one to many relationships. There everything from Retirement info, to benefit info, dependants info carried on coverage, Disability, etc. No way to use 1 recordsource and requires me to make chgs in like 10 diff forms.

          Thanks for the feedback though.

          Comment

          • Keriana30
            New Member
            • Nov 2007
            • 7

            #6
            Solved my own problem. At least so far. The only way to allow a main save and cancel function with subforms that use different recordsources is to programatically define the recordset based on query. Circle thru the recordset when you press Edit and use ReDim to define dynamic variable array and store the "old values" in variables. Then if user presses cancel, you can circle thru the recordset and reassign those old values. Its alot of work but so far it has the desired effect.

            Comment

            Working...