Refresh subform (1 Viewer)

Gismo

Registered User.
Local time
Tomorrow, 01:49
Joined
Jun 12, 2017
Messages
1,298
Hi all,

I am updating a form and after another form with a sunform must requery
Somehow it is not refreshing and the new record added does not appear in the drop down box of the sub form

If CurrentProject.AllForms(PurchaseOrder_GRV).IsLoaded Then
Forms![PurchaseOrder_GRV]![PurchaseOrderGRVSubForm].Form.Requery
End If
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:49
Joined
May 7, 2009
Messages
19,245
first, i think, you pass the Name of the form to AllForms:

If CurrentProject.AllForms("PurchaseOrder_GRV").IsLoaded Then
Forms![PurchaseOrder_GRV]![PurchaseOrderGRVSubForm].Form.Requery
End If

also you can directly requery the dropdown of the subform (and not the subform itself):

With Forms![PurchaseOrder_GRV]![PurchaseOrderGRVSubForm].Form!theComboxName
.RowSource = .RowSource
End With
 

Gismo

Registered User.
Local time
Tomorrow, 01:49
Joined
Jun 12, 2017
Messages
1,298
first, i think, you pass the Name of the form to AllForms:

If CurrentProject.AllForms("PurchaseOrder_GRV").IsLoaded Then
Forms![PurchaseOrder_GRV]![PurchaseOrderGRVSubForm].Form.Requery
End If

also you can directly requery the dropdown of the subform (and not the subform itself):

With Forms![PurchaseOrder_GRV]![PurchaseOrderGRVSubForm].Form!theComboxName
.RowSource = .RowSource
End With
Neither seems to work
No errors, new record just not available in the other forms sub form
 

ebs17

Well-known member
Local time
Tomorrow, 00:49
Joined
Feb 7, 2020
Messages
1,946
The drop down box and the subform have own data sources. So they need own requeries.

Code:
Forms![PurchaseOrder_GRV]![PurchaseOrderGRVSubForm].Form.Requery                   ' subform
Forms![PurchaseOrder_GRV]![PurchaseOrderGRVSubForm].Form.ComboBoxName.Requery      ' combobox
 

ebs17

Well-known member
Local time
Tomorrow, 00:49
Joined
Feb 7, 2020
Messages
1,946
You should rely less on luck when programming. Knowing what environment you are in and then planning your actions is far more effective than try & error & luck.

A Requery will of course only change something if the data in the tables has changed compared to the last data query or if the query definition has been changed, for example with a different filter.
Which of the above did you do and how exactly?
 

bob fitz

AWF VIP
Local time
Today, 23:49
Joined
May 23, 2011
Messages
4,727
Your subform is named PurchaseOrderGRVSubForm but does the SubForm Control on the main form have the same name
 

Gismo

Registered User.
Local time
Tomorrow, 01:49
Joined
Jun 12, 2017
Messages
1,298
Your subform is named PurchaseOrderGRVSubForm but does the SubForm Control on the main form have the same name
Hi,

No does not have the same name

I got this one sorted

Private Sub Close_Click()
On Error GoTo Close_Click_Err

If CurrentProject.AllForms(PurchaseOrder_GRV).IsLoaded Then
Forms![PurchaseOrder_GRV]![PurchaseOrderGRVSubForm].Form.Requery.RowSource = CBOProduct
End If
If CurrentProject.AllForms(PurchaseOrder_GRV_Asset).IsLoaded Then
Forms![PurchaseOrder_GRV_Asset]![PurchaseOrderGRVAssetSubForm].Form.Requery.RowSource = CBOProduct
End If
DoCmd.Close , ""


Close_Click_Exit:
Exit Sub

Close_Click_Err:
MsgBox Error$
Resume Close_Click_Exit

End Sub

This form has a sub form that needs to be updated

I am now looking at the same senario but the main form must requery, not the sub form

Seems like the same code wont work if there is no sub form with .RowSource
If CurrentProject.AllForms(PurchaseOrder_GRV).IsLoaded Then
Forms![PurchaseOrder_GRV].Requery.RowSource =CBOSupplier
End If
 

Gismo

Registered User.
Local time
Tomorrow, 01:49
Joined
Jun 12, 2017
Messages
1,298
All good thank you
Thanks for the assistance
 

Gismo

Registered User.
Local time
Tomorrow, 01:49
Joined
Jun 12, 2017
Messages
1,298
Hi all,

I am back to the same problem

When Products are updated, PurchaseOrder_GRV and PurchaseOrderGRVSubform does not requery

I tried al the below

If CurrentProject.AllForms(PurchaseOrder_GRV).IsLoaded Then
Forms![PurchaseOrder_GRV].Requery
Me.Recordset.Requery
Me.[Forms]![PurchaseOrder_GRV]![PurchaseOrderGRVSubForm].Form!CBOProduct.Recalc
Forms![PurchaseOrder_GRV]![PurchaseOrderGRVSubForm].Form!CBOProduct.Requery
Forms![PurchaseOrder_GRV]![PurchaseOrderGRVSubForm].Form.Requery.RowSource = CBOProduct
End If
If CurrentProject.AllForms(PurchaseOrder_GRV_Asset).IsLoaded Then
Forms![PurchaseOrder_GRV].Requery
Forms![PurchaseOrder_GRV_Asset]![PurchaseOrderGRVAssetSubForm].Form.Requery.RowSource = CBOProduct
End If
DoCmd.Close , ""
If CurrentProject.AllForms(PurchaseOrder_GRV).IsLoaded Then
Forms![PurchaseOrder_GRV].Requery
Me.Recordset.Requery
Forms![PurchaseOrder_GRV]![PurchaseOrderGRVSubForm].Form![CBOProduct].Requery
Forms![PurchaseOrder_GRV]![PurchaseOrderGRVSubForm].Form.Requery
Forms![PurchaseOrder_GRV]![PurchaseOrderGRVSubForm].Form.Requery.RowSource = CBOProduct
End If

If CurrentProject.AllForms(PurchaseOrder_GRV_Asset).IsLoaded Then
Forms![PurchaseOrder_GRV].Requery
Forms![PurchaseOrder_GRV_Asset]![PurchaseOrderGRVAssetSubForm].Form.Requery.RowSource = CBOProduct
End If
 

ebs17

Well-known member
Local time
Tomorrow, 00:49
Joined
Feb 7, 2020
Messages
1,946
does not requery
Code:
Forms![PurchaseOrder_GRV]![PurchaseOrderGRVSubForm].Form.Requery.RowSource = CBOProduct
There are a lot of errors here alone, so I would expect a sequence of runtime errors and the code would not even be executed.

When Products are updated
How and by what means is this done?
I think it would be easier for you to just close and reopen the forms. Then, like the subforms and combo boxes and list boxes, they have up-to-date data.
 

Gismo

Registered User.
Local time
Tomorrow, 01:49
Joined
Jun 12, 2017
Messages
1,298
Code:
Forms![PurchaseOrder_GRV]![PurchaseOrderGRVSubForm].Form.Requery.RowSource = CBOProduct
There are a lot of errors here alone, so I would expect a sequence of runtime errors and the code would not even be executed.


How and by what means is this done?
I think it would be easier for you to just close and reopen the forms. Then, like the subforms and combo boxes and list boxes, they have up-to-date data.
Currently I dont receive any runtime errors
I was also thinking of just closing and opening the form but I wanted to do it the correct way

Products are updated or amended in the main Products form only
There ae no subforms on the products form
 

ebs17

Well-known member
Local time
Tomorrow, 00:49
Joined
Feb 7, 2020
Messages
1,946
Currently I dont receive any runtime errors
I can not believe that. Does what you show come from the database you are actually working with? Have you ever debugged/compiled BA code? "On Error Resume Next" removed/commented?
 

Gismo

Registered User.
Local time
Tomorrow, 01:49
Joined
Jun 12, 2017
Messages
1,298
I can not believe that. Does what you show come from the database you are actually working with? Have you ever debugged/compiled BA code? "On Error Resume Next" removed/commented?
Yes, it is the same DB, I Debug and compile often
 

Minty

AWF VIP
Local time
Today, 23:49
Joined
Jul 26, 2013
Messages
10,371
This line looks to me like it can't ever run (It looks complete gibberish tbh!).

Code:
Forms![PurchaseOrder_GRV]![PurchaseOrderGRVSubForm].Form.Requery.RowSource = CBOProduct

It will get ignored during compilation because of the Forms! reference at the start of it, but if it ever actually got called you would get a runtime error.
 

Users who are viewing this thread

Top Bottom