I have a subform control xDetail on a main form frmMain.
xDetail can be loaded with a variety of forms (selected according to user actions in another subform) and may also have it's recordsource adjusted to display a subset of records.
The lines of code I have to do this are:
Public Sub LoadLinkedForm(pstrFormName As String, pstrSQL As String)
2260 On Error GoTo PROC_ERR
2270 Forms.frmmain!xDetail.SourceObject = pstrFormName
2280 Forms.frmmain!xDetail.Form.RecordSource = pstrSQL
2300 Exit Sub
2310 Select Case Err.Number
2330 End Select
2340 Resume PROC_EXIT
Often, but not always, when this code is run, I get either an error 2467 in the load event of the form being loaded or an error 2424 in the current event when the sourceobject is being set. In both cases, the code is referencing a control on the form (not the same control in the two events).
When the errors happen:
le = true
visible = true
eobject = "frmSource" 'This is an examle; it happens with a variety of forms.
name = "frmSource"
ce = "SELECT qrySource.* FROM qrySource WHERE qrySourceID = 39;"
If I run a query based on the recordsource, it returns a single record (as expected).
When the error 2467 occurs, if I examine "Me" in the Locals window, everything is showing "<>".
When the error 2424 occurs, "Me" in the locals window looks as I would expect, except that all of the controls have the value: The expression you entered has a field, control or property name that Access can't find.
The 2424 error also happens in the Current event sometimes when the recordsource is being changed.
The same forms can also be loaded into another subform on frmMain but I haven't *yet* seen them fail if they're loaded there?
I'm bemused as how how to proceed with this one.