Ken,
To clarify, My 'subform' child and master properties have always been
empty.
Though the subform is sitting in the mainform (frm_Runs), it has never
been
linked.
I tried your code, like this:
*************
Private Sub cbo_Point2Point_Postcode_To_AfterUpdate()
'DoCmd.SetWarnings False
Dim strSQL As String
strSQL = "SELECT TOP 9 tbl_Point_2_Point_2_Postcodes.Point2Point_ID,
tbl_Point_2_Point_2_Postcodes.Run_No,
tbl_Point_2_Point_2_Postcodes.Run_point_Venue,
tbl_Point_2_Point_2_Postcodes.Run_point_Address,
tbl_Point_2_Point_2_Postcodes.Run_Point_Postcode,
tbl_Point_2_Point_2_Postcodes.Point_ID1 FROM tbl_Point_2_Point_2_Postcodes
GROUP BY tbl_Point_2_Point_2_Postcodes.Point2Point_ID,
tbl_Point_2_Point_2_Postcodes.Run_No,
tbl_Point_2_Point_2_Postcodes.Run_point_Venue,
tbl_Point_2_Point_2_Postcodes.Run_point_Address,
tbl_Point_2_Point_2_Postcodes.Run_Point_Postcode,
tbl_Point_2_Point_2_Postcodes.Point_ID1 ORDER BY
tbl_Point_2_Point_2_Postcodes.Point2Point_ID DESC;"
Forms![frm_Runs]![frm_Point_2_Point_any_Postcodes_B].Form.LinkChildFields
= ""
Forms![frm_Runs]![frm_Point_2_Point_any_Postcodes_B].Form.LinkMasterFields
=
""
Forms![frm_Runs]![frm_Point_2_Point_any_Postcodes_B].Form.RecordSource =
strSQL
Forms![frm_Runs]![frm_Point_2_Point_any_Postcodes_B].Form.LinkChildFields
= ""
Forms![frm_Runs]![frm_Point_2_Point_any_Postcodes_B].Form.LinkMasterFields
=
""
DoCmd.OpenQuery "Qry_Point_2_Point_Postcodes_Delete"
DoCmd.OpenQuery "Qry_Point_2_Point_any_Postcodes"
'DoCmd.SetWarnings True
Forms![frm_Runs]![frm_Point_2_Point_any_Postcodes_B].Requery
Forms![frm_Runs]![frm_Point_2_Point_any_Postcodes_B].Form![tbl_Points.Run_point_Venue].Requery
End Sub
*************
But get an error:
Error: 2465
Application defined or object-defined error
and this line is highlighted yellow in the VBA window:
Forms![frm_Runs]![frm_Point_2_Point_any_Postcodes_B].Form.LinkChildFields
= ""
Ken Snell (MVP) said:
OK sorry. My code suggestion was based on an erroneous assumption that
the
subform was in the form that was running the code.
What you can do is to change the subform's LinkChildFields and
LinkMasterFields properties to an empty string before you set the
subform's
RecordSource property, and then do it again right after you set the
RecordSource:
Forms![frm_Runs]![frm_Point_2_Point_any_Postcodes_B].Form.LinkChildFields
=
""
Forms![frm_Runs]![frm_Point_2_Point_any_Postcodes_B].Form.LinkMasterFields
=
""
Forms![frm_Runs]![frm_Point_2_Point_any_Postcodes_B].Form.RecordSource =
strSQL
Forms![frm_Runs]![frm_Point_2_Point_any_Postcodes_B].Form.LinkChildFields
=
""
Forms![frm_Runs]![frm_Point_2_Point_any_Postcodes_B].Form.LinkMasterFields
=
""
--
Ken Snell
<MS ACCESS MVP>
Ken,
I kind of have it working with the code below with this line in
particular
seeming to make some difference:
Forms![frm_Runs]![frm_Point_2_Point_any_Postcodes_B].Form.RecordSource
=
strSQL
which gives first pops up a box asking me to 'Specify Relationship'
between
the subform (frm_Point_2_Point_any_Postcodes_B) and the master form
(frm_Runs). I don't want, or have to specfiy a relationship between the
two
forms as they are entirely unrelated.
and if I use (your original) line:
Me.frm_Point_2_Point_any_Postcodes_B.Form.RecordSource = strSQL
I just get a blank form.
*********************
DoCmd.SetWarnings False
Dim strSQL As String
strSQL = "SELECT TOP 9 tbl_Point_2_Point_2_Postcodes.Point2Point_ID,
tbl_Point_2_Point_2_Postcodes.Run_No,
tbl_Point_2_Point_2_Postcodes.Run_point_Venue,
tbl_Point_2_Point_2_Postcodes.Run_point_Address,
tbl_Point_2_Point_2_Postcodes.Run_Point_Postcode,
tbl_Point_2_Point_2_Postcodes.Point_ID1 FROM
tbl_Point_2_Point_2_Postcodes
GROUP BY tbl_Point_2_Point_2_Postcodes.Point2Point_ID,
tbl_Point_2_Point_2_Postcodes.Run_No,
tbl_Point_2_Point_2_Postcodes.Run_point_Venue,
tbl_Point_2_Point_2_Postcodes.Run_point_Address,
tbl_Point_2_Point_2_Postcodes.Run_Point_Postcode,
tbl_Point_2_Point_2_Postcodes.Point_ID1 ORDER BY
tbl_Point_2_Point_2_Postcodes.Point2Point_ID DESC;"
frm_Point_2_Point_any_Postcodes_B.Form.RecordSource = strSQL
'Forms![frm_Runs]![frm_Point_2_Point_any_Postcodes_B].Form.RecordSource
=
strSQL
DoCmd.OpenQuery "Qry_Point_2_Point_Postcodes_Delete"
DoCmd.OpenQuery "Qry_Point_2_Point_any_Postcodes"
DoCmd.SetWarnings True
Forms![frm_Runs]![frm_Point_2_Point_any_Postcodes_B].Requery
Forms![frm_Runs]![frm_Point_2_Point_any_Postcodes_B].Form![tbl_Points.Run_point_Venue].Requery
*********************
:
Open your main form in design view. Click on the top edge of the
subform.
Open the Properties window. Click on the Other tab. What is the value
in
the
Name box? That is the name of the subform control.
A subform is contained within a subform control -- that box that
contains
the subform form. That is the name that you must use in the
"Me.NameOfSubformControl.Form.RecordSource = strSQL" code step. Your
"name",
"frm_Point_2_Point_any_Postcodes_B", likely is the name of the form
that
you're using as the subform's SourceObject.
--
Ken Snell
<MS ACCESS MVP>
Ken,
The code didn't change the Record Source for the form.
Where you say "Me.NameOfSubformControl.Form.RecordSource = strSQL"
confuses
me because the Record Source is not linked to a specific control on
the
subform, but instead is linked to the Subform itself.
The Subform is called: [frm_Point_2_Point_any_Postcodes_B]
which is on a main form called [frm_Runs]
I have this code in the Afterupdate for the combo on the form
[frm_Runs]
Dim strSQL As String
strSQL = "SELECT TOP 9 tbl_Point_2_Point_2_Postcodes.Point2Point_ID,
tbl_Point_2_Point_2_Postcodes.Run_No,
tbl_Point_2_Point_2_Postcodes.Run_point_Venue,
tbl_Point_2_Point_2_Postcodes.Run_point_Address,
tbl_Point_2_Point_2_Postcodes.Run_Point_Postcode,
tbl_Point_2_Point_2_Postcodes.Point_ID1 FROM
tbl_Point_2_Point_2_Postcodes
GROUP BY tbl_Point_2_Point_2_Postcodes.Point2Point_ID,
tbl_Point_2_Point_2_Postcodes.Run_No,
tbl_Point_2_Point_2_Postcodes.Run_point_Venue,
tbl_Point_2_Point_2_Postcodes.Run_point_Address,
tbl_Point_2_Point_2_Postcodes.Run_Point_Postcode,
tbl_Point_2_Point_2_Postcodes.Point_ID1 ORDER BY
tbl_Point_2_Point_2_Postcodes.Point2Point_ID DESC;"
Me.frm_Point_2_Point_any_Postcodes_B.Form.RecordSource = strSQL
DoCmd.SetWarnings False
DoCmd.OpenQuery "Qry_Point_2_Point_Postcodes_Delete"
DoCmd.OpenQuery "Qry_Point_2_Point_any_Postcodes"
Forms![frm_Runs]![frm_Point_2_Point_any_Postcodes_B].Requery
Forms![frm_Runs]![frm_Point_2_Point_any_Postcodes_B].Form![tbl_Points.Run_point_Venue].Requery
what would I
:
Yes:
Private Sub NameOfComboBox_AfterUpdate()
Dim strSQL As String
strSQL = "The actual SQL Statement or Name of table/query"
Me.NameOfSubformControl.Form.RecordSource = strSQL
End Sub
--
Ken Snell
<MS ACCESS MVP>
Is it possible to change a Form's RecordSource from one table to
another
table on-the-fly?
The two tables are identical, except they use a set of two
different
criteria linked to two different pairs of combo boxes on the main
form
The subform is called: frm_Point_2_Point_any_Postcodes_B
Linked to a table with this RecordSource:
SELECT TOP 9 tbl_Point_2_Point_2.Point2Point_ID,
tbl_Point_2_Point_2.Run_No,
tbl_Point_2_Point_2.Run_point_Venue,
tbl_Point_2_Point_2.Run_point_Address,
tbl_Point_2_Point_2.Run_Point_Postcode,
tbl_Point_2_Point_2.Point_ID1
FROM
tbl_Point_2_Point_2 GROUP BY tbl_Point_2_Point_2.Point2Point_ID,
tbl_Point_2_Point_2.Run_No, tbl_Point_2_Point_2.Run_point_Venue,
tbl_Point_2_Point_2.Run_point_Address,