Results 1 to 6 of 6

Thread: Update text box on main form afterupdate of subform

  1. #1
    Join Date
    Jun 2010
    Location
    Kansas, USA
    Posts
    15

    Question Update text box on main form afterupdate of subform

    I have a text box located on the main form. I would like to requery the total given in the text box (based on a query) on the AfterUpdate event of a subform. I have a second subform that uses the same query and can get it to update fine, but the text box will requery the entire form. This would not be a problem, but the user can enter time for previous days, and therefore the requery moves the previous days records to the chronological order.

    The short, is on an AfterUpdate event on the subform, how can I requery just the text box on the main form?

    Thanks in advance

  2. #2
    Join Date
    May 2006
    Posts
    407
    how can I requery just the text box on the main form?
    Code:
    Me.Parent!JustTheOneField.ReQuery

  3. #3
    Join Date
    Jun 2010
    Location
    Kansas, USA
    Posts
    15
    GolferGuy I appreciate that, however it still requeries the entire form (form and subforms). The text box is based on the data input into one of the subforms, and if it gets requeried, it will move the records in the subform.

  4. #4
    Join Date
    May 2006
    Posts
    407
    It sounds like you are putting a total (total time entered so far maybe?). So, you can use "DSum" to calculate that total for you.
    Code:
    Me.Parent!JustTheOneField = DSum("YouTableFieldName", "YourTableName", "YourCriteria")
    YourTableFieldName is the field you need to sum, YourTableName is the name of the table, or query that has the field in it, and YourCriteria is the criteria to select only the records you want included in the sum.
    If you will be using all the records from the set you are using (table or query) then you don't need to include any criteria. The DSum will just use all the records in the set of records you name in the "YourTableName" parameter.

  5. #5
    Join Date
    Jun 2010
    Location
    Kansas, USA
    Posts
    15
    Brilliantly simple...

    I was using a DSum() and had it as the recordsource. I had just overlooked the fact that I could control the value from VBA, rather than requering the recordsource. I moved the DSum() to the default value and added your code to the After Update event on the subform and it works flawlessly.

    Thank you so much!

  6. #6
    Join Date
    May 2006
    Posts
    407
    Glad it's working.

Posting Permissions

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