Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Feb 2001
    Posts
    369
    Thanks
    2
    Thanked 1 Time in 1 Post

    When is data in table underlying form updated? (2000sp3)

    Apologies for stupid question, but I've found it difficult to design a search strategy to pick potential answers from the archive.

    If one changes the values of bound controls in a bound form, then requeries the form (or, in this case, the subform's form), when is the record in the underlying table updated? I have a subroutine that tries to manipulate data from the table underlying the form as a recordset subsequent to changing values of some controls and requerying, but the changes have not yet been incorporated into the record. Do I have to move away from the record in the subform as well as requerying its form? Would it make any difference if my subroutine opened the recordset as a recordsetclone of the subform's form rather than "directly" from the table.

    There are many ways round this, of course. I'd just like to understand what's going on.

    Thanks

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: When is data in table underlying form updated? (2000sp3)

    In your subroutine, include this before trying to manipulate the recordset:

    If Me.Dirty Then
    RunCommand acCmdSaveRecord
    End If

    This assumes that the subroutine is in the module behind the form.

  3. #3
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: When is data in table underlying form updated? (2000sp3)

    Just to clarify when data is saved on a bound form, it is saved in a number of situations:
    - When you move to another record.
    - When you move to a subform.
    - When you close the form.
    - When you requery the form.

    In a subform, the record is saved:
    - When you move to another record within the subform.
    - when you exit the subform back to the mainform.

    As Hans pointed out, you can force a save by using the RunCommand accmdSaveRecord. However, there is one gotcha here. If your form as any BeforeUpdate code that might cancel the update, you had better take this into account. I use code like this:
    If Me.Dirty then
    RunCommand acCmdSaveRecord
    If Me.Dirty then 'occurs if save failed!
    Exit sub
    End if
    End if
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •