I have a bit of a convoluted design which I will try to explain as best as I can so bear with me.
There is a full-screen form whose source is set to "Orders" (let's call it frmOrders). On it there's a few controls with order details and (1) a small continuous subform that displays a (filterable) list of all orders (frmList), and (2) a second subform that displays products that were part of this order (frmProducts).
We "solved" navigation using the following code:
Trouble is that it seems the order in which controls are loaded/initialized/constructed is not guaranteed. E.g. frmList's OnCurrent event would fire before its hosting parent form was loaded and calling Me.Parent.ShowOrder would fail with an error - hence we added a utility function to check if parent is loaded and query frmList for currently selected record in frmOrders's OnLoad event.
Then it worked for a while... until Access decided to load the frmList subform before loading the frmProducts subform seemingly for no reason at all. Now it's the subProducts.Form.ShowProductsFor call that is failing. We can bypass this by doing checks similar to ParentIsLoaded and then sprinkling some magic calls querying for currently selected order in frmProducts's OnLoad but... this seems a little backwards and doesn't feel sustainable in the long run.
(As a side note, we do realise we could link up Orders and Products using master/child fields but we need to do some ADO processing upon selection and from our testing the master/child linkage comes with the significant caveat of not having any event fire for child whenever its recordset is forced to change by master - thus preventing our ADO processing from knowing when to run.)
After this lengthy introduction: do you know of any event, any mechanism that we could employ to simply withold any processing until all subforms and controls are loaded, and then do what we have to do when they are? Are there any rules that govern subform/control initialization that we could reference to know in what order they would be loaded (= ready to interact with)? We have not been able to find anything useful in MS documentation. Have also had a look at these forums, but came back empty handed. How do you handle such intertwined "on-open" subform communication?
Wil be most grateful for any pointers or thoughts you might have that relate to this, one would think relatively common, use case.
There is a full-screen form whose source is set to "Orders" (let's call it frmOrders). On it there's a few controls with order details and (1) a small continuous subform that displays a (filterable) list of all orders (frmList), and (2) a second subform that displays products that were part of this order (frmProducts).
We "solved" navigation using the following code:
Code:
' Code for frmList
Private Sub Form_Current()
If UtilUi.ParentIsLoaded(Me) Then
Call Me.Parent.ShowOrder(Me!OrderId)
End If
End Sub
' Code for frmOrders
Public Sub ShowOrder(intOrderId As Integer)
DoCmd.SearchForRecord acDataForm, Me.Name, , "[OrderId] = " & intOrderId
Call subProducts.Form.ShowProductsFor(intOrderId)
End Sub
Private Sub Form_Load()
Call ShowOrder(subList.Form.SelectedOrder)
End Sub
' Code for frmProducts
Public Sub ShowProductsFor(intOrderId As Integer)
' Do some magic stuff here
End Sub
' Code in UtilUi
Public Function ParentIsLoaded(frm As Form) As Boolean
Dim obj As Object, rtn As Boolean
rtn = False
On Error Resume Next
Set obj = frm.Parent
If Err.Number = 0 Then
rtn = True
End If
Set obj = Nothing
On Error GoTo 0
ParentIsLoaded = rtn
End Function
Trouble is that it seems the order in which controls are loaded/initialized/constructed is not guaranteed. E.g. frmList's OnCurrent event would fire before its hosting parent form was loaded and calling Me.Parent.ShowOrder would fail with an error - hence we added a utility function to check if parent is loaded and query frmList for currently selected record in frmOrders's OnLoad event.
Then it worked for a while... until Access decided to load the frmList subform before loading the frmProducts subform seemingly for no reason at all. Now it's the subProducts.Form.ShowProductsFor call that is failing. We can bypass this by doing checks similar to ParentIsLoaded and then sprinkling some magic calls querying for currently selected order in frmProducts's OnLoad but... this seems a little backwards and doesn't feel sustainable in the long run.
(As a side note, we do realise we could link up Orders and Products using master/child fields but we need to do some ADO processing upon selection and from our testing the master/child linkage comes with the significant caveat of not having any event fire for child whenever its recordset is forced to change by master - thus preventing our ADO processing from knowing when to run.)
After this lengthy introduction: do you know of any event, any mechanism that we could employ to simply withold any processing until all subforms and controls are loaded, and then do what we have to do when they are? Are there any rules that govern subform/control initialization that we could reference to know in what order they would be loaded (= ready to interact with)? We have not been able to find anything useful in MS documentation. Have also had a look at these forums, but came back empty handed. How do you handle such intertwined "on-open" subform communication?
Wil be most grateful for any pointers or thoughts you might have that relate to this, one would think relatively common, use case.