Disabling subform depending on mainform value

tb5038

Registered User.
Local time
Today, 12:04
Joined
Jan 6, 2014
Messages
32
Hi,

I have a mainform called frm_Main containing the field AgeCalc

I then have a a subform which has some tabs, one of those tabs contains a subform called frm_Bans.

If the AgeCalc field is <17 I want to disable the subform frm_Bans.

Any ideas? Im a novice with coding but coping so far!

Thanks in advance
 
In you main form in Design View go to the Event tab and in the OnCurrent select Event Procedure.

Now put in this:

Code:
If Me.AgeCalc[B]ControlName[/B]< 17 Then
Me.frm_Bans.Form.Visible = False
Else: Me.frm_Bans.Form.Visble=True
End If


For this to work properly you must use the control names so the name of the control on the form (go to Other tab and see the Name--change the name to something that makes sense).

BTW, I like to precede subforms with subfrm instead of frm since I have a ton of forms and it makes it easier.
 
Thanks for the tip about subform names.

Ive tried the code, works great. Only problem is the form I want to control is on a tabbed page within subform. does that make any difference?
 
Only problem is the form I want to control is on a tabbed page within subform. does that make any difference?
No, but I think that will be ugly and annoying for the user to enter in that tab and to see... nothing.
So, in my opinion is better to hide the tab at all:
Code:
Me.TabCtlName.Pages(PageIndex).Visible = (Me.AgeCalcControlName>=  17)

'or

Me.TabCtlName.Pages("PageName").Visible = (Me.AgeCalcControlName >= 17)
The PageIndex is a number (integer) that is 0(zero) for the first page

Also, take a look here:
http://office.microsoft.com/en-us/access-help/using-the-tab-control-on-a-form-HA001230049.aspx

Good luck !
 

Users who are viewing this thread

Back
Top Bottom