Solved CHange record source of subform (1 Viewer)

chrisjames25

Registered User.
Local time
Today, 14:40
Joined
Dec 1, 2014
Messages
404
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.
 
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:
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.
 
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
 
BTW when you change the recordsource, no need to requery, that in itself is a requery.
 

Users who are viewing this thread

Back
Top Bottom