DSum isn't updating from subform

phoust

New member
Local time
Today, 07:34
Joined
Aug 20, 2024
Messages
10
I have a form with a subform. On the parent form, there is an unbound text box that calculates the total of the records on the subform. On the subform, on a double-click on a record, a form opens to edit or delete the record clicked. There are two buttons on this subform, one to save the record and one to delete. On both buttons, there are macros to close the form, open the parent form and requery. The subform displays the edited record, or if deleted, does not show the deleted record. However, the unbound text box on the parent does not update to reflect this change. Since I have the requery in the macro, I'm not sure what to do to get the parent form to update with the new total.
 
However, the unbound text box on the parent does not update to reflect this change.
Try on AfterUpdate event of SubForm
Code:
Private Sub Form_AfterUpdate()
    If FormHasParent(Me) Then
        Me.Parent.Form.YourUboundTextBox.Requery
    End If
End Sub

Private Function FormHasParent(objForm As Form) As Boolean
' Checking that the form, at the moment, is displayed as subform
'--------------------------------------------------------------------
On Error GoTo FormHasParent_Err
    FormHasParent = TypeName(objForm.Parent.Name) = "String"
    Exit Function
FormHasParent_Err:
    Err.Clear
End Function
Replace "YourUboundTextBox" to your TextBox name.
 
Recalc the parent form. I don't use macros, so I don't know the macro command, but in VBA code it's Me.Parent.Recalc.
 
When you open the third form, open it model. Then when that form closes. Code resumes at the line after the OpenForm. Requery the subform using Me.Requery. That is the single line of VBA code that is required.
 

Users who are viewing this thread

Back
Top Bottom