Solved Correct Way Of Referring To A Subform Control (1 Viewer)

Local time
Today, 15:19
Joined
Feb 27, 2022
Messages
49
Hi guys,

I've got a form with two subforms on it. (The form's name is "PrepOrders" in case this info is required)

I'm not sure (even after reading and watching a few demo's) how to correctly refer to one of the subforms control?

I have this code:
Code:
If Me.AllocatedTotal > Me!frmNetPurchasedInventory.Form!MaxPackagesAvail Then

where "Allocated Total" is on subform2 and what I'm trying on subform2 is to refer to a control on subform1 called "MaxPackagesAvail". Subform2's name is "frmNetPurchasedInventory".

Could someone please correct what I'm doing wrong?

Thanking you
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:49
Joined
Oct 29, 2018
Messages
19,134
Looks like you're using it for the BrowseTo method in A Navigation Form, is that correct?
 
Last edited:
Local time
Today, 15:19
Joined
Feb 27, 2022
Messages
49
I'm sorry, I don't know what the BrowseTo method is.

Within the open form (and obviously two subforms that reside in it), I want to check the value of on control on subform1, against the value of another control on Subform2 and fire up a messagebox if certainly conditions are met.

But with the code I tried above, Access tells me "Microsoft Access can't find the field 'frmNetPurchasedInventory' referred to you in your expression. So I know I haven't been successful in how to refer to the control in Subform2.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 00:49
Joined
Feb 28, 2001
Messages
23,117
Generally, from the parent form, referring to a control on a subform requires you to know the name of the control holding the subform, but you don't need the name of the subform itself for that reference.

Me.SubformControlName.Form.ControlNameOnSubForm
 

keviny04

New member
Local time
Yesterday, 22:49
Joined
Mar 28, 2018
Messages
5
When you are in subform2 and want to refer to subform1, you need to refer to the PARENT of subform1 also:

Code:
If Me.AllocatedTotal > Parent!frmNetPurchasedInventory.Form!MaxPackagesAvail Then

The parent of subform1 and 2 is your main form, PrepOrders. You can also refer to your main form by name:

Code:
If Me.AllocatedTotal > Forms("PrepOrders")!frmNetPurchasedInventory.Form!MaxPackagesAvail Then
or
Code:
If Me.AllocatedTotal > Forms!PrepOrders!frmNetPurchasedInventory.Form!MaxPackagesAvail Then
 
Local time
Today, 15:19
Joined
Feb 27, 2022
Messages
49
Generally, from the parent form, referring to a control on a subform requires you to know the name of the control holding the subform, but you don't need the name of the subform itself for that reference.

Me.SubformControlName.Form.ControlNameOnSubForm
Thank you The_Doc_Man.
 
Local time
Today, 15:19
Joined
Feb 27, 2022
Messages
49
When you are in subform2 and want to refer to subform1, you need to refer to the PARENT of subform1 also:

Code:
If Me.AllocatedTotal > Parent!frmNetPurchasedInventory.Form!MaxPackagesAvail Then

The parent of subform1 and 2 is your main form, PrepOrders. You can also refer to your main form by name:

Code:
If Me.AllocatedTotal > Forms("PrepOrders")!frmNetPurchasedInventory.Form!MaxPackagesAvail Then
or
Code:
If Me.AllocatedTotal > Forms!PrepOrders!frmNetPurchasedInventory.Form!MaxPackagesAvail Then
Hi keniny04,

This is super easy to understand and I now clearly get how to do it. Thank you for showing me both options too. It makes sense.

Appreciate you and The_Doc_Man for teaching me this.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 01:49
Joined
Feb 19, 2002
Messages
36,837
Just FYI, subforms typically have multiple records so exactly which record in sfrm1 do you want to compare with sfrm2? By default, the first record in each subform is the "current" record but if you have scrolled one or more of the subforms a different record may be current and it is ALWAYS and ONLY the current record in a subform that you are referring to with the code you have been given.

This doesn't seem like a sound plan. What are you comparing and why will the values always be in the current records of the two subforms?
 
Local time
Today, 15:19
Joined
Feb 27, 2022
Messages
49
Thank you for clarifying the 'current' record. That makes sense. For this particular application, I was comparing records of a summed total in the footer of both subforms.

The first subform contains data about the number of products that are available for allocation (more like a read only form) and the second subform allows the user to allocate products and create product bundles where applicable.
 

Users who are viewing this thread

Top Bottom