Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I hide columns on tab control subform?

Status
Not open for further replies.

midiman69

Technical User
Apr 27, 2005
34
GB
Can any one help with a problem I have with a tab control form

I have a form with a two page tab control - page 1 being the main form. I have a data sheet view subform on page 2.(linked by "Parttype"
There is a part type field on page 1 and I wish to hide columns on the data sheet depending on what part type is displayed on page 1.
I have tried this

Private Sub Form_Open(Cancel As Integer)

If Me.partype = "Resistor 0.25W 5%" Then

Forms!form2![frm_subres_0_25W_spec].Form![wattage].ColumnHidden = True

Else
Forms!form2![frm_subres_0_25W_spec].Form![wattage].ColumnHidden = False
End If
End Sub

Of course it doesn't work!
I may also want to be able to hide mulitple columns - how would I achieve this.

Can any on help me out? - Cheers
 
Hey Midiman,

On the After Update Event of you partype field on page/tab 1
try this:

If Me.partype = "Resistor 0.25W 5%" Then
Me.frm_subres_0_25W_spec!wattage.ColumnHidden = True

Else
Me.frm_subres_0_25W_spec!wattage.ColumnHidden = False

End If
 
Hi ssatech

Many thanks for the quick reply.
I tried your suggestion - still doesn't hide the column on subform.
I got the code slightly back to front on my original post
should be:

If Me.partype = "Resistor 0.25W 5%" Then
Me.frm_subres_0_25W_spec!wattage.ColumnHidden = True

Else
Me.frm_subres_0_25W_spec!wattage.ColumnHidden = False

End If


Any other suggestions?
 
This code hides the column for me. I don't see why its not
working for you.

-Did try putting the code in the after update event of the partype field.
-What is the data type for this partype field?
-Is this field a textbox or combo?
-I am assuming the name of your subform is: "frm_subres_0_25W_spec" and the field you are trying to hide is "wattage"
- In Design View of your tab form. Go to Tab 2 right-click for properties on your subform. Make sure the "Name...." under Other is "frm_subres_0_25W_spec" as well.

 
Are there any errormessages? Is "frm_subres_0_25W_spec" both the form name, as viewed in the database window AND the subform control name, which is used in referencing?

If so, try:

[tt]Me![frm_subres_0_25W_spec].Form!wattage.ColumnHidden = True[/tt]

Else, try invoking the expression builder from the main form, doubleclick through forms, loaded forms, main form, subform, then the control on the subform - and you should have correct reference.

Roy-Vidar
 
Hi ssatech

Yes I put the code in the after update event in the partype field

Partype data type is text

Field is a text box - source tblpartype

and yes sub form is frm_subres_0_25W_spec and the field is Wattage.

How very strange - I can't see anything wrong???
 
-AND the subform control name, which in Design View of your tab form. Go to Tab 2 right-click for properties on your subform. Make sure the "Name...." under Other is "frm_subres_0_25W_spec" as well. Is this correct too.

-Have you tried Roy-Vidar's suggestion:

If Me.partype = "Resistor 0.25W 5%" Then
Me![frm_subres_0_25W_spec].Form!wattage.ColumnHidden = True

Else
Me![frm_subres_0_25W_spec].Form!wattage.ColumnHidden = False
End If

-Try to clear the field manually (cut & paste "Resistor 0.25W 5%" from the field & tab out of the field, see what happens. Paste "Resistor 0.25W 5%" into the field again & tab out...and see if anything happens.

-Are you getting any errors?
 
Hi ssatech

My code is as follows:

If Me!partype = "Resistor 0.25W 5%" Then

Me![frm_subres_0_25W_spec].Form!wattage.ColumnHidden = False
Else
Me![frm_subres_0_25W_spec].Form![wattage].ColumnHidden = True

When I cut and paste it seems to work - not getting any error messages.
Would a combo box improve things?
 
You could use a combo box or the On Lost Focus event.
Which ever way your data entry works.....
 
Cracked it!

Put the code on the form "On Current" event and it works fine.

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top