Solved CHange record source of subform (1 Viewer)

chrisjames25

Registered User.
Local time
Today, 10:41
Joined
Dec 1, 2014
Messages
401
Hi. I have a main form with the name Frm_PottingInput. WIthin that form is a subform called Frm_Sub_Potting. The source object of that form is called Frm_BatchInputSubform.

I have a option button on the frm_pottinginput form that when i click i want to change the recordsource of Frm_BatchInputSubform.

THe code i am currently using is :

Code:
Forms!Frm_PottingInput!Frm_batchinputsubform.Form.RecordSource = "Qry_PottingDataPrintedTrue"

This is not yeilding the result i want. I have also tried

Code:
Forms!Frm_PottingInput!Frm_Frm_sub_potting.Form.RecordSource = "Qry_PottingDataPrintedTrue"

But neither do what i want and change the record source.

ANy ideas would be greatly appreciated. I get so confused with sub forms and the source objects within subforms.
 

Edgar_

Active member
Local time
Today, 04:41
Joined
Jul 8, 2023
Messages
430
CurrentDb.QueryDefs("Qry_PottingDataPrintedTrue").sql

maybe


Edited, read wrong.

Use this instead:
Form_Frm_BatchInputSubform.RecordSource = "Qry_PottingDataPrintedTrue"

Just make sure "Frm_BatchInputSubform" is open, otherwise it will open it for you. Also make sure only that form instance is loaded.
 
Last edited:

June7

AWF VIP
Local time
Today, 01:41
Joined
Mar 9, 2014
Messages
5,472
Normally a subform is linked to main form on primary/foreign key fields in which case filter would be applied to main form and subform "tags along" and shows only related records.
 

chrisjames25

Registered User.
Local time
Today, 10:41
Joined
Dec 1, 2014
Messages
401
When the code is in a form, I always use Me?

So Me.subformCONTROLNAME.Form.Recordsource.

Keep this link handy. http://access.mvps.org/access/forms/frm0031.htm
Above code doesn's cause me any code to fail but it doesnt seem to change the recodsource.

Code:
Private Sub Opt_Inactive_Click()
'Me.Cmd_Hidden.SetFocus
Me.Opt_Active.DefaultValue = False
Me.Opt_Inactive.DefaultValue = True
Me.Opt_All.DefaultValue = False
Me.Frm_SubPotting.Form.RecordSource = "Qry_PottingDataPrintedTrue"

'Me.Frm_Subform.Form!Text54.SetFocus

Me.Frm_SubPotting.Requery

End Sub

I have checked the qry and it is all set correctly.

IGNORE ALL THE ABOVE THAT SOLVED IT PERFECTLY. GASMAN YOU HAVE SAVED ME AGAIN. MANY THANKS
 

Gasman

Enthusiastic Amateur
Local time
Today, 10:41
Joined
Sep 21, 2011
Messages
14,301
BTW when you change the recordsource, no need to requery, that in itself is a requery.
 

Users who are viewing this thread

Top Bottom