update a query count on main form when subform is updated

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • DeanL

    update a query count on main form when subform is updated

    Hi everyone,

    I have a subform in datasheet view that is used to display the
    contents of a single table. I have another subform with a query
    feeding it to give a count of how many particular items are in the
    table and wanted to ask how I go about updating the count when I
    delete a value from the datasheet subform without closing and
    reopening the form?

    Many thanks for any help you can offer...

    Dean...
  • Rich P

    #2
    Re: update a query count on main form when subform is updated

    Try

    Me.Requery

    in the main form's Current Event. The idea is to trap an event on the
    main form when you make a change in the subform. Or another thing to
    try would be to do a
    me.Subform2.Req uery (where Subform2 is your 2nd subform) - but you have
    to trap the event in the first subform when you make a change. And one
    more thing would be to trap the Current Event of the first Subform -
    then you could do something like this:

    Private Sub Form_Current()
    Forms!your2ndSu bform.Requery
    End Sub

    The main thing is to requery the Query when you change something on the
    first subform.

    Rich

    *** Sent via Developersdex http://www.developersdex.com ***

    Comment

    • Tom van Stiphout

      #3
      Re: update a query count on main form when subform is updated

      On Fri, 13 Jun 2008 08:17:04 -0700 (PDT), DeanL
      <deanpmlonghurs t@yahoo.comwrot e:

      Requery like Rick suggested may work, but I think there is a more
      elegant solution. Recall that Excel recomputes formulas without you
      having to click a recalc button. Access can do that too: it knows
      which expressions depend on which ones, builds a tree and recomputes
      without you asking for it.

      In your situation I would put a textbox in the footer of subform1,
      with a controlsource of:
      =count(MyPrimar yKeyField)
      Let's call this control txtCountOfRows

      Then in the second subform you pick up that value:
      =Me.Parent.MySu bformControl1.F orm.txtCountOfR ows
      This control will automatically show the new value if the rowcount in
      subform1 changes.

      -Tom.

      >Hi everyone,
      >
      >I have a subform in datasheet view that is used to display the
      >contents of a single table. I have another subform with a query
      >feeding it to give a count of how many particular items are in the
      >table and wanted to ask how I go about updating the count when I
      >delete a value from the datasheet subform without closing and
      >reopening the form?
      >
      >Many thanks for any help you can offer...
      >
      >Dean...

      Comment

      Working...