Subform visible/not visible (1 Viewer)

ptodd

New member
Local time
Today, 15:49
Joined
Mar 24, 2015
Messages
8
I have a form "Order Summary"(main form) and two sub forms. I would like to display one or the other sub from based on a check box (retail) on the main form. This is "on current" of form.

Me.ShipToAddressTablesubformRetail.Visible = Me.Retail
Me.Ship_To_Address_Table_subform.Visible = Not Me.Retail

I have also tried this

If Me![Retail] = True Then
Forms!OrderSummary.Form.ShipToAddressTablesubformRetail.Visible = True
Forms!OrderSummary.Form.Ship_To_Address_Table_subform.Visible = False
Else
Forms!OrderSummary.Form.ShipToAddressTablesubformRetail.Visible = False
Forms!OrderSummary.Form.Ship_To_Address_Table_subform.Visible = True
End If
 

CJ_London

Super Moderator
Staff member
Local time
Today, 21:49
Joined
Feb 19, 2013
Messages
16,713
In principle your first code should work. So what is the problem? You get an error? Subform visibility doesn’t change? Something else?
 

isladogs

MVP / VIP
Local time
Today, 21:49
Joined
Jan 14, 2017
Messages
18,275
The code should be in the click event of the Retail checkbox
Omit the .Form

Shorten it to
Code:
If Me.Retail Then
    Me.ShipToAddressTablesubformRetail.Visible = True
    Me.Ship_To_Address_Table_subform.Visible = False
Else
    Me.ShipToAddressTablesubformRetail.Visible = False
    Me.Ship_To_Address_Table_subform.Visible = True
End If

Or better still, use what you originally wrote

Code:
    Me.ShipToAddressTablesubformRetail.Visible = Me.Retail
    Me.Ship_To_Address_Table_subform.Visible = Not Me.Retail
 
Last edited:

ptodd

New member
Local time
Today, 15:49
Joined
Mar 24, 2015
Messages
8
In principle your first code should work. So what is the problem? You get an error? Subform visibility doesn’t change? Something else?
When the form is initially opened, it works fine, But when scrolling through data, if the ShipToAddressTablesubformRetail is visible, then you go to the next record and this record does not have Retail checked, it still displays the retail subform vs Ship_To_Address_Table_subform.Visible
 

CJ_London

Super Moderator
Staff member
Local time
Today, 21:49
Joined
Feb 19, 2013
Messages
16,713
So the retail checkbox is bound to a field in the underlying table of the main form?

scrolling doesn’t change the current record - that will only happen when that record receives the focus. What is the main form? Single or continuous?
 

ptodd

New member
Local time
Today, 15:49
Joined
Mar 24, 2015
Messages
8
So the retail checkbox is bound to a field in the underlying table of the main form?

scrolling doesn’t change the current record - that will only happen when that record receives the focus. What is the main form? Single or continuous?
My bad, scrolling was the wrong word to use. I meant clicking on the navigation buttons to go forward or backward.
Yes. The retail checkbox is in the "OrderHeader" table that is the record source for the main form. The main form is single
 

CJ_London

Super Moderator
Staff member
Local time
Today, 21:49
Joined
Feb 19, 2013
Messages
16,713
So your first code should work. I presume the

ShipToAddressTablesubformRetail

is the name of the subform control

might be an idea for you to compact your db, zip and upload to the thread so we can see what is going on
 

ptodd

New member
Local time
Today, 15:49
Joined
Mar 24, 2015
Messages
8
So your first code should work. I presume the

ShipToAddressTablesubformRetail

is the name of the subform control

might be an idea for you to compact your db, zip and upload to the thread so we can see what is going on
ShipToAddressTablesubformRetail is the name of the subform used for retail customers
Ship_To_Address_Table_subform is the name of the subform used for wholesale customers
 

CJ_London

Super Moderator
Staff member
Local time
Today, 21:49
Joined
Feb 19, 2013
Messages
16,713
and the other one?

repeat, suggest you upload a copy of your db - remove any sensitive data and objects not relevant to the problem but leave enough to demo the problem
 

Users who are viewing this thread

Top Bottom