Question

I have a form with two subforms (1 and 2). Subform 1 stores the data continously for account breakdowns. Using a pop-up subform (subform 2), the user enters data to change or update the account breakdown stored on subform 1. On submit, the information is stored in the sub-table linked to subform 1, but the data does not refresh and add the new information in a new record in subform 1 unless I manually click the refresh all button in the home tab.

So far, I have tried the following code on form_afterupdate of subform 2, which does requery subform 1 automatically but creates a run-time error (2450) when the main form is closed:

Private Sub Form_AfterUpdate()

On Error GoTo Err_Form_AfterUpdate

Forms!frmSpendPlan!frmSpendPlanSub.Form.Requery

Exit_Form_AfterUpdate:

Exit Sub

Err_Form_AfterUpdate:

MsgBox Err.Description

Resume Exit_Form_AfterUpdate

End Sub

If anyone has a way to automatically requery subform 1 data once subform 2 is submitted without creating an error please let me know, I appreciate any help you can provide.

Thanks!

Was it helpful?

Solution

I have the same problem as you sometimes! The form doesn't refresh properly.

Method 1

try this line of code instead of the current requery code. It shouldn't give you an error but may still not work due to bugs...

Form_frmSpendPlanSub.Requery

I use this format to reference across forms and it works well usually.

Method 2

1) What you can try is in design view click on the form that is doing the "After_Update"

2) Right-Click on the form and click "BUILD EVENT.." and select "Expression Builder"

In expression builder you can see exactly how the form you are in links to the form you want to get to and what you want to do...

So you would navigate yourself by going to FORMS--> Loaded Forms--> frmSpendPlanSub and then from the list you can double click on " " This will get you referenced to the form you want to affect. Then all you have to do is copy the code that it gives you in the box above into your VBA code and then reference what you want to do...

E.g.

Forms![frmMainForm]![frmSecondForm].Form![frmThirdForm].Form.Requery

Anyway hope that helps...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top